First: Thank you, Richard for all the fun you have provided me and my brother.
Second: I wrote a game that uses the number keys to control movement, but the NUMBER LOCK must be ON for this to work correctly. Is there a way my program can turn the NUMBER LOCK ON if it is OFF? Yes, I really tried, but this must be above my pay grade!
Many thanks to anybody who can help me,
Joe Skittone
NUMBER LOCK
-
- Posts: 177
- Joined: Mon 02 Apr 2018, 21:51
Re: NUMBER LOCK
Hello,
I had a quick look and I'm not sure that there's an easy solution for this problem. At least on linux there's a tool called numlockx which does what you want, but it requires installation and so is not convenient, and it's for linux which I assume you're not using.
I could well be wrong though and maybe there is a way.
Still, I would suggest that you change the keys used by your game, perhaps using the letter keys instead, if this is possible, since it seems like the easiest solution. Also, not every keyboard has a number pad.
PM
I had a quick look and I'm not sure that there's an easy solution for this problem. At least on linux there's a tool called numlockx which does what you want, but it requires installation and so is not convenient, and it's for linux which I assume you're not using.
I could well be wrong though and maybe there is a way.
Still, I would suggest that you change the keys used by your game, perhaps using the letter keys instead, if this is possible, since it seems like the easiest solution. Also, not every keyboard has a number pad.
PM
-
- Posts: 3
- Joined: Fri 13 Apr 2018, 07:44
Re: NUMBER LOCK
Thank you, Patrick M, for even thinking about my question. I just want the number pad IN ADDITION to other input methods.
Off Topic:
I'm not really a big "forum fan" but I'm certainly glad that this exists! It has come to my attention that a certain "Richard" has been "banned" from this venue on pain of a few knowledgeable members leaving. This is absurd! It is tantamount to banning Saint Peter from Heaven. Sure, Lucifer was banned from Heaven... but for CAUSE. What could this "Richard" have possibly done to deserve this treatment?
Off Topic:
I'm not really a big "forum fan" but I'm certainly glad that this exists! It has come to my attention that a certain "Richard" has been "banned" from this venue on pain of a few knowledgeable members leaving. This is absurd! It is tantamount to banning Saint Peter from Heaven. Sure, Lucifer was banned from Heaven... but for CAUSE. What could this "Richard" have possibly done to deserve this treatment?
Re: NUMBER LOCK
Hi Joe,
I only know the answer for BBC Basic for Windows,though I guess there may be similar commands in the SDL version.
To test for whether num lock is set or not, you can use SYS "GetKeyState". Here I return the result in a variable nl%, which will be 0 if it is not set, and 1 if it is.
You can toggle num lock using SYS "keybd_event" to mimic a key press: you can specify key pressed and then key released.
Here's some code to test the state, and set it if it isn't set:
Hope that's useful,
D
I only know the answer for BBC Basic for Windows,though I guess there may be similar commands in the SDL version.
To test for whether num lock is set or not, you can use SYS "GetKeyState". Here I return the result in a variable nl%, which will be 0 if it is not set, and 1 if it is.
You can toggle num lock using SYS "keybd_event" to mimic a key press: you can specify key pressed and then key released.
Here's some code to test the state, and set it if it isn't set:
Code: Select all
VK_NUMLOCK = &90
SYS "GetKeyState",VK_NUMLOCK TO nl%
IF nl%=0 THEN
SYS "keybd_event",VK_NUMLOCK,0,0,0 :REM Numlock pressed
SYS "keybd_event",VK_NUMLOCK,0,2,0 :REM Numlock released
ENDIF
SYS "GetKeyState",VK_NUMLOCK TO nl%
D
Re: NUMBER LOCK
Oh, and as an aside, Richard is NOT banned from the forum, he has chosen not to post. He has had conflicts in the past with some other members, and is concerned that if he returns their expertise will be lost from the forum. From my perspective, he'd be very welcome to return, and I am working to try to facilitate that.
Best wishes,
D
Best wishes,
D
Re: NUMBER LOCK
I've had a bit of a look at the SDL version. It looks like you can detect Numlock being set (or not) with SDL_GetModState: a value of 4096 (i.e. bit 12 set) seems to indicate num lock is on. Similarly, bit 13 (8192) seems to indicate caps lock is set.
There's an equivalent SDL_SetModState which does seem to allow you to change the values, but doesn't seem to result in actual toggling of the key - but that could easily be because I'm doing it wrong/not providing a required parameter...
There's an equivalent SDL_SetModState which does seem to allow you to change the values, but doesn't seem to result in actual toggling of the key - but that could easily be because I'm doing it wrong/not providing a required parameter...
Code: Select all
SYS "SDL_GetModState" TO s%
PRINT s%
SYS "SDL_SetModState",s% OR 4096
SYS "SDL_GetModState" TO s%
PRINT s%
-
- Posts: 177
- Joined: Mon 02 Apr 2018, 21:51
-
- Posts: 3
- Joined: Fri 13 Apr 2018, 07:44
Re: NUMBER LOCK
Dear DDRM,
THANK YOU! This is exactly what I need.
Respectfully,
Joe Skittone
PS
Thanks for the "Richard" information. That guy is an inspiration to me and (I'm sure)
many others. I suspect that he always reads this board.
THANK YOU! This is exactly what I need.
Respectfully,
Joe Skittone
PS
Thanks for the "Richard" information. That guy is an inspiration to me and (I'm sure)
many others. I suspect that he always reads this board.
-
- Posts: 327
- Joined: Wed 04 Apr 2018, 06:36
Re: NUMBER LOCK
Some time ago I needed to know (and set) the CapsLock key and someone kindly provided me with this routine. It requires a byte array K%, which I have set to 255
DIMK%255
:
DEFPROCcapsoff:LOCALf%,cmd$
SYS"GetKeyboardState",K%
IFK%?20THEN
ipfile$=CHR$34+@tmp$+"myscript.vbs"+CHR$34
f%=OPENOUTipfile$
PRINT#f%,"Set WshShell = CreateObject( ""WScript.Shell"" )"
PRINT#f%,"WshShell.SendKeys ""{CAPSLOCK}"""
CLOSE#f%
cmd$="cscript "+ipfile$
OSCLI("RUN "+cmd$)
OSCLI("DEL "+ipfile$+CHR$34)
ENDIF
ENDPROC
I don't know whether it can be adapted to set the NumLock key?
DIMK%255
:
DEFPROCcapsoff:LOCALf%,cmd$
SYS"GetKeyboardState",K%
IFK%?20THEN
ipfile$=CHR$34+@tmp$+"myscript.vbs"+CHR$34
f%=OPENOUTipfile$
PRINT#f%,"Set WshShell = CreateObject( ""WScript.Shell"" )"
PRINT#f%,"WshShell.SendKeys ""{CAPSLOCK}"""
CLOSE#f%
cmd$="cscript "+ipfile$
OSCLI("RUN "+cmd$)
OSCLI("DEL "+ipfile$+CHR$34)
ENDIF
ENDPROC
I don't know whether it can be adapted to set the NumLock key?