Page 2 of 3
Re: detecting capslock key down
Posted: Mon Jul 12, 2021 6:07 pm
by richmond62
Unless, like me, you keep 2 BBC Micros running, you had better modify that to
shiftLock happened.

Re: detecting capslock key down
Posted: Mon Jul 12, 2021 8:03 pm
by dunbarx
The OP wants a message to be sent by virtue of pressing the capsLock key. All the other (very workable) solutions essentially use either a function directly or interrogation of the state of the capsLock key, basically the same thing.
I have never needed this, but am curious if it pans out.
I miss Hermann too.
Craig
Re: detecting capslock key down
Posted: Mon Jul 12, 2021 8:10 pm
by richmond62
On Linux and Windows one should be able to get a rawKeyCode for the capsLock key.
Code: Select all
on rawKeyDown KD
put KD
end rawKeyDown
As far as I know the Macintosh KMAP does not help much.
Currently on a MacMini . . .
BUT if one has this sort of code:
Code: Select all
on rawKeyDown KD
put the keysDown into fld "KEYZDOWN"
end rawKeyDown
you can discover that the rawKeyCode for
capslock is 65509
by pressing a letter key with the capslock DOWN.
Mind you, how the flying fudgebucket you can work out WHEN the capslock is actually pressed down
on a Macintosh escapes me.
BUT, it is a dead-groovy way of getting the rawKeyCodes on a Macintosh for SHIFT, ALT, CTRL, COMMAND and so forth.
THIS does NOT work:
Code: Select all
on rawKeyDown KD
if KD = 65509 then
put "pressed the capslock" into fld "OOT"
else
put empty into fld "OOT"
end if
end rawKeyDown
Re: detecting capslock key down
Posted: Mon Jul 12, 2021 8:48 pm
by richmond62
On a Linux box pressing the capslock key LiveCode picks up a rawKeyCode.
So much for Macintosh.
Re: detecting capslock key down
Posted: Tue Jul 13, 2021 8:40 am
by richmond62
You could code for this sort of thing:
Code: Select all
if item 2 of the keysDown is 65509 then
--Jump and shout
end if
But it presupposes another key is also being pressed, or another key is being pressed after the capslock key
has been depressed (and is locked down).
IFF the capslock is DOWN (i.e. has already been pressed) then
in a button, for instance
will report 65509
The difference between keysDown and keyDown is that the former one reports a state, while the latter one reports an action.
Re: detecting capslock key down
Posted: Tue Jul 13, 2021 8:58 am
by richmond62
The problem is that in the Macintosh world pressing the capslock key either does NOT send a rawKey signal
(which seems odd as the processor has to register that the capslock key is being depressed) to the CPU, or
LiveCode doesn't/can't pick a rawKey signal up, this smells odd as LiveCode can detect when the capslock key IS down.
Re: detecting capslock key down
Posted: Tue Jul 13, 2021 9:26 am
by richmond62
"Dirty types" might have a poke around in this:
https://github.com/wo52616111/capslock-plus
Re: detecting capslock key down
Posted: Tue Jul 13, 2021 2:00 pm
by dunbarx
which seems odd as the processor has to register that the capslock key is being depressed
None of the five "control-style" keys (option, control, shift, command, capsLock) respond to the "rawkeyDown" message. I am not sure I can think of any case where such a response would be useful, since all of those keys are only pertinent in conjunction with another key.
For example, if I press the "x" key, I get "120" as the param from "rawKeyDown", whereas, if the either the capsLock or shiftKey is down at that moment, I get "88".
So, as usual, Macintosh reduces clutter.
Craig
Re: detecting capslock key down
Posted: Tue Jul 13, 2021 4:10 pm
by richmond62
Not if, for some odd reason you have got it into your head that you want to use the capsLock key
for something other thandoing what a capsLock key usually does.
So, as usual, Macintosh reduces clutter.
And makes it less hackable by those who want to do other things.
Re: detecting capslock key down
Posted: Tue Jul 13, 2021 5:16 pm
by dunbarx
Richmond.
I am all for creating a new message, or at least rawKeyDown awareness, when one of those five keys are pressed. Certainly this might be used to initiate some personal predefined function. I wonder if there is something deep down that makes such a thing difficult.
Craig
Re: detecting capslock key down
Posted: Tue Jul 13, 2021 7:42 pm
by richmond62
rawKeyDown awareness
Aha: next year, at about this time, I shall be presenting online
rawKeyDown Awareness Classes
complete with navel-gazing, mantras and juju beads.

Re: detecting capslock key down
Posted: Wed Jul 14, 2021 5:39 pm
by jacque
I wonder if there is something deep down that makes such a thing difficult.
The usual reason is that the OS doesn't report it, so LC can't see it either.
Re: detecting capslock key down
Posted: Wed Jul 14, 2021 7:44 pm
by richmond62
that the OS doesn't report it
Indeed.
So in my favourite "ideal world" [don't worry, I've already got a therapist . . . admittedly she is out in the
garden at the moment teasing lizards and grasshoppers . . . she's extremely level headed: whatever crap
I throw at her she just says 'miaow' or yawns], LiveCode would do one of two things:
1. Bypass MacOS (probably nearly impossible).
2. Somehow lever
keysDown . . .
What has to be faced is that MacOS (and Windows, although to a lesser extent) is all about 3 things:
1. Forcing everyone on to the bed of Procrustes . . .
https://en.wikipedia.org/wiki/Procrustes
2. Dumbing things down.
3. Not allowing end-users to do much fiddling around round behind the smoke and mirrors.
Oh, as per Procrustes, I am so glad that I grew up before educationalists decided that children might
be traumatised by Greek legends and the original Grimms' Fairy Tales.
Re: detecting capslock key down
Posted: Sun Aug 29, 2021 4:14 pm
by PaulDaMacMan
I just noticed this thread while looking for something else...
I've used rawKeyDown in conjunction with a capsLock check to do things with the caps lock that have nothing to do with capitalization, which I see similar solutions have been mentioned. I've also used an array of key codes for similar, perhaps even slightly faster, end results.
The problem might have something to do with keyboard scan matrix in the design of most modern computer keyboards, rather than purely for some nefarious motives. This matrix can be rather perplexing and annoying when you want to use an alphanumeric keyboard as a musical instrument to play chords
https://www.musiccrowns.org/viral/evan- ... keyboards/
But it is true that the macOS does not forward certain special key signals such as media keys (play/pause/stop) to Applications. By default the "Play" key launches iTunes for example (although I've seen hacks that override that), or that now defunct FrontRow thing (that was the predecessor to AppleTV)
From that AppleScriptObjC code that was posted, it seems you can get a signal from capsLock key press on macOS but the LC engine doesn't send one. This could be a job for LiveCode Builder FFI!
Re: detecting capslock key down
Posted: Sun Aug 29, 2021 7:26 pm
by richmond62
the macOS does not forward certain special key signals
So, macOS does pick up raw key signals when keys are depressed, it has been programmed NOT
to pass ones on, unlike with Windows and Linux.