How to tell if Capslock is on

BlitzMax Forums/BlitzMax Beginners Area/How to tell if Capslock is on

Will(Posted 2005) [#1]
How do I determine if CapsLock is down?


xlsior(Posted 2005) [#2]
Look for the little light on your keyboard? ;-)


Seriously though -- good question.
A quick test shows that the keycode returned when you *press* caps-lock is 20.

(Duh. And *after* the fact of finding this out I see that there is indeed a predefined constant of Key_Capslock that is set to 20) Anyway, that doesn't do a whole lot of good I guess, since it doesn't tell you the current state, just whether or not someone is actively holding it down at the moment.

The recently added GetChar() doesn't seem to detect Caps Lock at all (Since it isn't actually a character key, and has no ASCII value to return obviously)


Beaker(Posted 2005) [#3]
On Windows:
Strict

SetCapsLockKey(1)	'1 for ON
End


Function SetCapsLockKey(newState)
	Const KEYEVENTF_KEYUP = $2
	Const vbKeyCapital = 20
	' if the current state must be changed
	If GetKeyState(vbKeyCapital) <> newState
		' programmatically press and release the CapsLock key
		keybd_event vbKeyCapital, 0, 0, 0
		keybd_event vbKeyCapital, 0, KEYEVENTF_KEYUP, 0
	EndIf
End Function

Extern "win32"
	
	Function keybd_event(bVk, bScan, dwFlags, dwExtraInfo)
	Function GetKeyState(nVirtKey)
		
End Extern
Use:
GetKeyState(vbKeyCapital)
to check status.


Will(Posted 2005) [#4]
wait, what is this GetChar() command I hear about - is it only available after the core update?


Prym(Posted 2016) [#5]
Good morning Beaker,
Is it necessary to install a bookshop before?
( Extern Win32 , keybd_event , GetKeyState(nVirtKey) ??? )
If it is the only resolution, I would like I shall apply it.
Thank you.

Bonjour Beaker ,
Est-ce qu'il faut installer une librairie auparavant ?
( Extern Win32 , keybd_event , GetKeyState(nVirtKey) ??? )
Si c'est la seule solution, j'aimerais pouvoir l'appliquer .
Merci .

Prym


Prym(Posted 2016) [#6]
ça y est ! ça a marché !
Je l'ai utilisé dans galaxangint03 :

http://galaxangint.livehost.fr/
Merci .