detecting capslock key down

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: detecting capslock key down

Post by richmond62 » Mon Jul 12, 2021 6:07 pm

Unless, like me, you keep 2 BBC Micros running, you had better modify that to

shiftLock happened. 8)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: detecting capslock key down

Post by dunbarx » Mon Jul 12, 2021 8:03 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: detecting capslock key down

Post by richmond62 » Mon Jul 12, 2021 8:10 pm

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

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: detecting capslock key down

Post by richmond62 » Mon Jul 12, 2021 8:48 pm

On a Linux box pressing the capslock key LiveCode picks up a rawKeyCode.

So much for Macintosh.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: detecting capslock key down

Post by richmond62 » Tue Jul 13, 2021 8:40 am

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

Code: Select all

put the keysDown
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.
Last edited by richmond62 on Tue Jul 13, 2021 9:02 am, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: detecting capslock key down

Post by richmond62 » Tue Jul 13, 2021 8:58 am

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.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: detecting capslock key down

Post by richmond62 » Tue Jul 13, 2021 9:26 am

"Dirty types" might have a poke around in this:

https://github.com/wo52616111/capslock-plus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: detecting capslock key down

Post by dunbarx » Tue Jul 13, 2021 2:00 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: detecting capslock key down

Post by richmond62 » Tue Jul 13, 2021 4:10 pm

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. 8)
So, as usual, Macintosh reduces clutter.
And makes it less hackable by those who want to do other things.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: detecting capslock key down

Post by dunbarx » Tue Jul 13, 2021 5:16 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: detecting capslock key down

Post by richmond62 » Tue Jul 13, 2021 7:42 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: detecting capslock key down

Post by jacque » Wed Jul 14, 2021 5:39 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: detecting capslock key down

Post by richmond62 » Wed Jul 14, 2021 7:44 pm

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.

PaulDaMacMan
Posts: 627
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: detecting capslock key down

Post by PaulDaMacMan » Sun Aug 29, 2021 4:14 pm

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 :lol:
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!
Last edited by PaulDaMacMan on Mon Aug 30, 2021 9:25 pm, edited 1 time in total.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: detecting capslock key down

Post by richmond62 » Sun Aug 29, 2021 7:26 pm

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.

Post Reply

Return to “Talking LiveCode”