Caps Lock on?

Anything QL Software or Programming Related.
Post Reply
issue5
ROM Dongle
Posts: 28
Joined: Fri Mar 26, 2021 5:41 pm

Caps Lock on?

Post by issue5 »

Hi, just a quick and easy question (for someone) - how do you turn CAPS LOCK on from within a Superbasic program?
Cheers
Keith


Silvester
Gold Card
Posts: 436
Joined: Thu Dec 12, 2013 10:14 am
Location: UK

Re: Caps Lock on?

Post by Silvester »

Politely

10 PRINT "Dear user, please press CAPSLOCK" :D

Crudely POKE 163976,255 turns on, POKE 163976,0 off (QDOS, other OS best to use POKE!!136 variation - see docs)


David
User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: Caps Lock on?

Post by dilwyn »

I guess that if you wanted to be a bit less impolite to the system and ensure you use system variables at the correct location by using VER$ to use the more polite version on systems where the system variables may be somewhere else:

v$ = VER$
IF v$ = 'JSL1' OR v$ = 'HBA' THEN POKE !!136,255 : ELSE POKE 163976,255

In case you haven't come across it before, the POKE !! variant is effectively just an offset from the base of the system variables, e.g. if they start at 163840 then the 136 is just the difference between 163840 and 163976. Also, according to documentation, the system variable is technically a word length, although changing the first byte alone will usually work.

Uses the Minerva/SBASIC enhancements where relevant - note that for some reason I've read somewhere - possibly one of Simon Goodwin's bugs articles - that the VER$ should be assigned to a variable as on some ROM versions there is a stack error which means that using it in IF statements directly under some conditions can lock the system. The IF statement simply ensures that it doesn't try to use the POKE!! variation on Sinclair ROM systems which don't support it.

I'm not sure if this poke will work on an emulator anyway, it doesn't seem to work on QPC2 when I did a quick check just now. You can read the current value from it, but looks like it can't be set for understandable reasons.

Instead of trying to force CAPS LOCK on, might be better to use a couple of lines of BASIC to force the result of a keyboard read to upper case, or use '==' string equivalence to ensure both upper and lower case letters are both recognised. Conveniently, the CODE values of upper and lower case letters are 32 different, so you can force upper or lower case by subtracting or adding 32. Some examples:

key = CODE(INKEY$))
SELect ON key = 97 TO 122 : key = key-32

k$ = INKEY$
IF k$ >= 'a' AND k$ <= 'z' THEN k$ = CHR$(CODE(k$)-32)

k$ = INKEY$
IF k$ == 'a' THEN .....

(Sorry, that got a bit longer than I intended, hope it's useful).


User avatar
bwinkel67
QL Wafer Drive
Posts: 1196
Joined: Thu Oct 03, 2019 2:09 am

Re: Caps Lock on?

Post by bwinkel67 »

dilwyn wrote:I
I'm not sure if this poke will work on an emulator anyway, it doesn't seem to work on QPC2 when I did a quick check just now. You can read the current value from it, but looks like it can't be set for understandable reasons.
It works on QLAY2...I know, I know, not peoples choice for a QL emulator. I got dropped too many times as a kid I guess :-/


User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: Caps Lock on?

Post by dilwyn »

bwinkel67 wrote:
dilwyn wrote:I
I'm not sure if this poke will work on an emulator anyway, it doesn't seem to work on QPC2 when I did a quick check just now. You can read the current value from it, but looks like it can't be set for understandable reasons.
It works on QLAY2...I know, I know, not peoples choice for a QL emulator. I got dropped too many times as a kid I guess :-/
:lol:


Silvester
Gold Card
Posts: 436
Joined: Thu Dec 12, 2013 10:14 am
Location: UK

Re: Caps Lock on?

Post by Silvester »

Ah, a while after posting reply I then thought about mentioning '=='.

Unfortunately my favourite editor (MasterSpy) has an annoying habit of poking the key repeat rates when starting and then restoring them when leaving. Although it can deal with multiple files/views I still find it easier to start/close other instances ad hoc - then the fun begins.

I guess I used to get poked to many times as kid, don't like it :lol:


David
User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: Caps Lock on?

Post by mk79 »

dilwyn wrote:I'm not sure if this poke will work on an emulator anyway, it doesn't seem to work on QPC2 when I did a quick check just now. You can read the current value from it, but looks like it can't be set for understandable reasons.
Yes, I cannot deviate from the Windows CapsLock setting, so either it's not possible to programmatically change CapsLock in Windows or I didn't know how or I didn't bother because it's a bad idea anyway, I don't remember.
Instead of trying to force CAPS LOCK on, might be better to use a couple of lines of BASIC to force the result of a keyboard read to upper case
Exactly this. If you want uppercase input, make your input uppercase. There are also utility functions for doing this to whole strings somewhere.


Post Reply