NUMBER LOCK

Discussions related to mouse, keyboard and Graphical User Interface
Post Reply
Joe Skittone
Posts: 3
Joined: Fri 13 Apr 2018, 07:44

NUMBER LOCK

Post by Joe Skittone » Sat 29 Sep 2018, 22:46

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

Patrick M
Posts: 99
Joined: Mon 02 Apr 2018, 21:51

Re: NUMBER LOCK

Post by Patrick M » Sun 30 Sep 2018, 11:12

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
P.M.

Joe Skittone
Posts: 3
Joined: Fri 13 Apr 2018, 07:44

Re: NUMBER LOCK

Post by Joe Skittone » Sun 30 Sep 2018, 22:00

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?

DDRM
Administrator
Posts: 82
Joined: Mon 02 Apr 2018, 18:04

Re: NUMBER LOCK

Post by DDRM » Mon 01 Oct 2018, 17:02

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:

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%
Hope that's useful,

D

DDRM
Administrator
Posts: 82
Joined: Mon 02 Apr 2018, 18:04

Re: NUMBER LOCK

Post by DDRM » Mon 01 Oct 2018, 17:05

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

DDRM
Administrator
Posts: 82
Joined: Mon 02 Apr 2018, 18:04

Re: NUMBER LOCK

Post by DDRM » Mon 01 Oct 2018, 17:53

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...

Code: Select all

      SYS "SDL_GetModState" TO s%
      PRINT s%
      SYS "SDL_SetModState",s% OR 4096
      SYS "SDL_GetModState" TO s%
      PRINT s%

Patrick M
Posts: 99
Joined: Mon 02 Apr 2018, 21:51

Re: NUMBER LOCK

Post by Patrick M » Wed 03 Oct 2018, 00:49

DDRM wrote:
Mon 01 Oct 2018, 17:05
From my perspective, he'd be very welcome to return, and I am working to try to facilitate that.
Sorry to go offtopic, but I would just like to say that I agree with this. I would be happy to see Richard return to the forums.

PM
P.M.

Joe Skittone
Posts: 3
Joined: Fri 13 Apr 2018, 07:44

Re: NUMBER LOCK

Post by Joe Skittone » Tue 09 Oct 2018, 04:56

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.

Post Reply