A simple demo to show how we can use DECLARE LIBRARY to get the initial key state of CapsLock, NumLock, and ScrollLock, and how we can use QB64 to change them for us, if wanted.
DECLARE LIBRARY
FUNCTION GetKeyState% (BYVAL nVirtKey AS LONG)
SUB keybd_event (BYVAL bVK AS _BYTE, BYVAL bScan AS _BYTE, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS _OFFSET)
END DECLARE
VK_CAPITAL = &H14
VK_NUMLOCK = &H90
VK_SCROLLLOCK = &H91
DO
LOCATE 1, 1
PRINT GetKeyState(VK_CAPITAL), GetKeyState(VK_NUMLOCK), GetKeyState(VK_SCROLLLOCK)
a$ = INKEY$
SELECT CASE a$
CASE "c", "C"
keybd_event VK_CAPITAL, &H45, 1, 0
keybd_event VK_CAPITAL, &H45, 3, 0
CASE "n", "n"
keybd_event VK_NUMLOCK, &H45, 1, 0
keybd_event VK_NUMLOCK, &H45, 3, 0
CASE "s", "S"
keybd_event VK_SCROLLLOCK, &H45, 1, 0
keybd_event VK_SCROLLLOCK, &H45, 3, 0
CASE CHR$(27)
SYSTEM
CASE ""
CASE ELSE
PRINT a$
END SELECT
_LIMIT 30
LOOP
This prints 3 values on the screen for us -- one for each keystate our OS/program might be in. To toggle the values, hit C for caps lock, N for num lock, and S for scroll lock. (It wouldn't make much sense to do a demo where we hit the actual keys and watched the values change -- this little program does the work for us WITHOUT having to press those keys.)
NOTE: This only works for Windows (as far as I know, since these are windows API calls).
NOTE 2: If you notice, there's no library actually listed in the DECLARE LIBRARY statement. That's because QB64 already has declared these functions, and we're just making use of them naturally.
Since these functions are already available inside libqb, they'd be a breeze to implement into the language as a set of new keywords. If several people see the need/use of adding a _CAPSLOCK function/sub (and same for the other keys), let me know and I'll add them into the language for us.
If added, all one would have to do is something like:
PRINT _CAPSLOCK 'to print a value to tell us if it's currently ON or OFF.
_CAPSLOCK ON 'to set it on
_CAPSLOCK OFF 'to set it off
Just ask yourself, is it worth adding multiple new words to the language to support these functions? Or is it better to just leave them as DECLARE LIBRARY statements, as per the demo above, and not add to the ever-growing list of keywords?