Page 1 of 1

Num lock on

Posted: Sat Jan 07, 2006 11:54 pm
by John_Schofield
Hi

Is there a way to ensure that the num lock key effectively stays on throughout a program, even if accidentally pressed? Sort of along the lines of "If num lock turned off, num lock turned on again".

I have a small program which records a sequence of numbers, some of which may have to be typed quickly, and it is all too easy to accidentally catch the num lock key which would then prevent further number entry via the numeric keypad until the problem was spotted.

The program executes a section of code every second using the On Timer function (as it runs a clock as well) so it's possible that the checking routine could be there.

This would have to also work when the program is compiled for distribution to any pc user, including those who may be running XP, as I want to circulate compiled copies once I've finished development, rather than the quickbasic source code..

Any ideas chaps? :?: :?

The only thought I've come up with so far is to drill a hole in the key and put a pin through it once num lock is set!

Posted: Tue Jan 10, 2006 8:23 am
by Valerie
Test the numlock bit and set it ON if at any time it's turned off accidentally.

Posted: Tue Jan 10, 2006 9:44 am
by John_Schofield
Valerie wrote:Test the numlock bit and set it ON if at any time it's turned off accidentally.
How do I do that? Sounds simple but it's one of those things you either know how to do or not!

Numlock coding

Posted: Wed Jan 11, 2006 10:22 am
by Valerie
The following code checks if the Numlock bit in the Keyboard Data Byte is ON and if not turns it ON. It has been tested in Windows 98se QBasic 4.5 IDE. It has not been compiled & run nor has it been tested in Win.XP.

Code: Select all

DEF SEG = 0
inbyte = PEEK(&H417)  ' Put the byte at &H417 into variable inbyte
IF (inbyte AND 32) THEN       ' Check if the Num-lock bit is ON
   ELSE POKE &H417, PEEK(&H417) OR 32     ' Set Num-lock bit ON
END IF
DEF SEG

Good luck with your projects.

V...

Posted: Wed Jan 11, 2006 11:03 am
by John_Schofield
Thanks Valerie. Should be ok for me as I use Win98 and QB4.5.

Testing the compiled version should be simple enough in that environment.

Of course, as XP has "no dos" background this may not work in that OS but all I can do is give it a go!

I'm very grateful for your help

Yes, agree

Posted: Wed Jan 11, 2006 10:40 pm
by Valerie
Thanks for coming back - lots of posters don't.

Agree that there may be a problem with XP, it has the nasty habit of "hiding" things from non-MS programmers. Sorry, I don't run XP so can't help you with it, I'm strictly not an NT fan..

Cheers again

V...

Manners

Posted: Thu Jan 12, 2006 12:06 am
by John_Schofield
Just good manners that's all! Obliged for any assistance.

best wishes

John