Set or Unset the keyboard numlock and read its stateTag(s): Win API

This code will toggle the keyboard NUM LOCK state.
OleObject wsh
Integer  li_rc

wsh = CREATE OleObject
li_rc = wsh.ConnectToNewObject( "WScript.Shell" )

See this HowTo for a list of special keys that can be used (like CAPSLOCK).

To read the NUM LOCK state

[local function declaration]
FUNCTION  int GetKeyState(int keystatus) LIBRARY "user32.dll"


int li_keystate

li_keystate = GetKeyState(144)

IF li_keystate = 1 THEN
    MessageBox("", "NUMLOCK on")
ELSEIF li_keystate = 0 THEN
    MessageBox("", "NUMLOCK off")

blog comments powered by Disqus