SetKeyboardstate is the only I didn't try jet.
Eric
------------------
Announcement
Collapse
No announcement yet.
Switch CAP-LOCK On/Off
Collapse
X
-
I was finally able to get the numLock light to work by adding the SetKeyboardState.
Now the function seems to work properly for all three keyboard lights, at least for
Windows 98 SE and the three keyboards that I have to test. Thanks Peter and Eric P.
for your help.
Code:#COMPILE EXE #DIM ALL #INCLUDE "win32api.inc" DECLARE SUB SetNumLock(VKkey AS LONG, bState AS BYTE) FUNCTION PBMAIN() 'SetNumLock %VK_CAPITAL, %TRUE 'SetNumLock %VK_CAPITAL, %FALSE 'SetNumLock %VK_SCROLL, %TRUE 'SetNumLock %VK_SCROLL, %FALSE SetNumLock %VK_NUMLOCK, %TRUE 'SetNumLock %VK_NUMLOCK, %FALSE END FUNCTION SUB SetNumLock(VKkey AS LONG, bState AS BYTE) 'Turn on and off caps lock, scroll lock and num lock 'VKkey = %VK_CAPITAL, %VK_SCROLL, %VK_NUMLOCK 'bState = %TRUE for on, %FALSE for off DIM keyState(256) AS BYTE LOCAL pKeyState AS BYTE PTR pKeyState = VARPTR(keyState(0)) GetKeyboardState BYVAL pKeyState IF ((bState AND NOT (keyState(VKkey) AND 1)) OR (NOT bState AND (keyState(VKkey) AND 1))) THEN Keybd_event VKkey, 0, %KEYEVENTF_EXTENDEDKEY, 0 Keybd_event VKkey, 0, %KEYEVENTF_EXTENDEDKEY + %KEYEVENTF_KEYUP, 0 keyState(VKkey) = bState SetKeyboardState BYVAL pKeyState END IF END SUB
------------------
Leave a comment:
-
Unfortunately not all keyboard lock-lights take their cues from the signals that are supplied by the computer. Less expensive keyboards simply count the number of times that the button has been physically pressed, so switching the lock state programmatically will affect the operation of the keyboard, but the lights will not indicate the actual keyboard state.
At least this used to be true. I haven't played with it for several years...
-- Eric
------------------
Perfect Sync: Perfect Sync Development Tools
Email: mailto:[email protected][email protected]</A>
Leave a comment:
-
Charles,
It turns the NumLock lite on and off on my system (Win2000)
------------------
Peter Amick
Baybuild Solutions
Leave a comment:
-
Eric,
I converted the C++ code from the following MS web site to PowerBasic.
http://support.microsoft.com/support.../Q127/1/90.ASP
It toggles my keyboard lights for Caps Lock and Scroll Lock, but for
some reason, the Num Lock light is not toggled on and off. However,
GetKeyboardState shows that the Num Lock state is toggled. Does
anyone out there have an explanation for this?
Code:#COMPILE EXE #DIM ALL #INCLUDE "win32api.inc" DECLARE SUB SetNumLock(VKkey AS LONG, bState AS BYTE) FUNCTION PBMAIN() 'SetNumLock %VK_CAPITAL, %FALSE 'SetNumLock %VK_CAPITAL, %TRUE 'SetNumLock %VK_SCROLL, %TRUE 'SetNumLock %VK_SCROLL, %FALSE SetNumLock %VK_NUMLOCK, %TRUE 'SetNumLock %VK_NUMLOCK, %FALSE END FUNCTION SUB SetNumLock(VKkey AS LONG, bState AS BYTE) DIM keyState(256) AS BYTE LOCAL pKeyState AS BYTE PTR pKeyState = VARPTR(keyState(0)) GetKeyboardState BYVAL pKeyState IF ((bState AND NOT (keyState(VKkey) AND 1)) OR (NOT bState AND (keyState(VKkey) AND 1))) THEN Keybd_event VKkey, 0, %KEYEVENTF_EXTENDEDKEY, 0 Keybd_event VKkey, 0, %KEYEVENTF_EXTENDEDKEY + %KEYEVENTF_KEYUP, 0 END IF END SUB
Leave a comment:
-
http://support.microsoft.com/support.../Q177/6/74.ASP
For recommended titles of Windows books... See the FAQ forum for a list and ISBN references.
------------------
Lance
PowerBASIC Support
mailto:[email protected][email protected]</A>
Leave a comment:
-
Switch CAP-LOCK On/Off
Hi
I am looking for the best way to switch the Caps-lock key.
I found keyb_event
keydown: keybd_event %VK_CAPITAL, 0, 0,0
keyup : keybd_event %VK_CAPITAL, 0, %KEYEVENTF_KEYUP,0
But this has the disadvantage that I'm not sure if I am switching On Or Off.
So I use GetKeyState(%VK_Capital) first to check the state.
Now I'm wondering if there is a direct API call or memory address where I could set the Caps Lock no matter what state it is in?
I really need to buy a good Win32API bible any sugestions would be welcome too.
Thanks for help
Eric Kelderman
Tags: None
Leave a comment: