On-screen Caps Lock Key Status

Share your advanced PureBasic knowledge/code with the community.
georgej
User
User
Posts: 11
Joined: Wed Aug 17, 2005 5:21 pm

On-screen Caps Lock Key Status

Post by georgej »

Code updated for 5.20+

This is an on-screen display of the Caps Lock key status. It is a small modification to Joakim Christiansen's code for a Desktop Clock.

Code: Select all

; --------------------------------------------------------------------------
; Title:    Caps Lock Key Status
; Version:  1.0
; PB Ver:   4.02
;
; Original code (Desktop Clock): Joakim Christiansen
; Small code modification (Caps Lock key status): George Jopling
;
; About:
; On-screen display of Caps Lock key status.
;
; --------------------------------------------------------------------------

OpenWindow(0,GetSystemMetrics_(0)/2-25,0,110,18, "Caps Lock Status", #PB_Window_BorderLess)
SetWindowPos_(WindowID(0),#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
ButtonGadget(0,100,0,10,18,"")

Repeat
  Select WaitWindowEvent(100)
    Case #WM_LBUTTONDOWN
      SendMessage_(WindowID(0),#WM_SYSCOMMAND,#SC_MOVE+#HTCAPTION,0)
    Case #PB_Event_Gadget
      End
  EndSelect
 
  StartDrawing(WindowOutput(0))
  DrawingMode(1)
  Box(0,0,100,18,#Black)
 
  If GetKeyState_(#VK_CAPITAL)
    DrawText(2,1, "Caps Lock: On",#Yellow)
  Else
    DrawText(2,1,"Caps Lock: Off",#Yellow)
  EndIf
 
  StopDrawing()

ForEver