detecting capslock key down
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
detecting capslock key down
Is the only way to detect if the capslockkey is down to monitor its state continuously? e.g. via a function called with send every second or so?
E.g. here and elsewhere in the archives
viewtopic.php?f=9&t=31626
Seems a rather inelegant way of doing things - I hate having to poll state....
There's no key event we can use to monitor capslock state?
~ Rodney
E.g. here and elsewhere in the archives
viewtopic.php?f=9&t=31626
Seems a rather inelegant way of doing things - I hate having to poll state....
There's no key event we can use to monitor capslock state?
~ Rodney
-
- VIP Livecode Opensource Backer
- Posts: 9663
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: detecting capslock key down
Hi.
Unlike to the other "control"-style keys, option, command, etc. which have messages sent when you press them, the capsLock key does not seem to have its own.
Only a function, the "capsLockKey" tells you what that key is up to, and functions have to be explicitly queried by you under script control.
Craig
Unlike to the other "control"-style keys, option, command, etc. which have messages sent when you press them, the capsLock key does not seem to have its own.
Only a function, the "capsLockKey" tells you what that key is up to, and functions have to be explicitly queried by you under script control.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: detecting capslock key down
I see there's also an eventCapsLockKey function that tells you if caps lock was enabled when an event began, as opposed to the current time. Depending on what you need, that might work. The dictionary isn't very clear about what an event is in this case.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: detecting capslock key down
Code: Select all
on keyUp KUP
if the capsLockKey is down then
put "DOWN" into fld "ff"
else
put "UP" into fld "ff"
end if
end keyUp
The Dictionary is your friend.
- Attachments
-
- CapsLocker.livecode.zip
- Here's the stack.
- (895 Bytes) Downloaded 113 times
Re: detecting capslock key down
Looks like the options are to either check the state of capslockKey with other events like keyUp, rawKeyDown, etc, or poll for it at regular intervals.
Whats' the context if you don't mind me asking?
Whats' the context if you don't mind me asking?
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: detecting capslock key down
Thanks for the replies, interesting about eventCapsLockKey Jacque, I hadn't run across that one.
I have a small productivity app I am building and I am trying to support context switching with minimal keyboard use. Caplock is a very large, single, lit, key and in my observation not much used by people - so it's ideal for frequent use. Easier to reach than function keys (which are often tiny or need modifiers to access these days).
But it doesn't generate events, it can only be polled via the supported function calls (unless user types a key with capslock down, but I am interested in operation of the capslock key itself).
I am going to add a feature request for capslock key event.
~ Rodney
I have a small productivity app I am building and I am trying to support context switching with minimal keyboard use. Caplock is a very large, single, lit, key and in my observation not much used by people - so it's ideal for frequent use. Easier to reach than function keys (which are often tiny or need modifiers to access these days).
But it doesn't generate events, it can only be polled via the supported function calls (unless user types a key with capslock down, but I am interested in operation of the capslock key itself).
I am going to add a feature request for capslock key event.
~ Rodney
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: detecting capslock key down
You can poll the state of the capsLock key right now . . .
- Have a button that contains this sort of code:
and then, in your function / mainscript this:
obviously you are unlikely to dump the result into a field as my example does . . .
- Have a button that contains this sort of code:
Code: Select all
on mouseUp
if the capsLockKey is down then
put "DOWN" into fld "ff"
else
put "UP" into fld "ff"
end if
end mouseUp
Code: Select all
send "mouseUp" to btn "checkCapsL"
- Attachments
-
- capsLox.livecode.zip
- Here's the stack.
- (1000 Bytes) Downloaded 129 times
Re: detecting capslock key down
Yes, but as I noted above, it's an inelegant approach....richmond62 wrote: ↑Mon Jul 12, 2021 6:49 amYou can poll the state of the capsLock key right now . . .
...
But it seems, the only way to do it at the moment.
~ Rodney
Re: detecting capslock key down
For those who are curious, you can detect state of control keys including capslock from applescript
Code: Select all
use AppleScript version "2.4" -- The ability to use ASObjC in running scripts was introduced in Mac OS 10.10.
use framework "Foundation"
use framework "AppKit" -- NSEvent is an AppKit class.
use scripting additions -- In case needed.
on modifierKeysPressed()
set modifierKeysDOWN to {capslock_down:false, command_down:false, option_down:false, control_down:false, shift_down:false}
set currentModifiers to current application's class "NSEvent"'s modifierFlags()
tell modifierKeysDOWN
-- 65536 capslock key
set its capslock_down to (currentModifiers div 65536 mod 2 is 1)
-- 524288: NSAlternateKeyMask constant in Mac OS 10.10 & 10.11/NSEventModifierFlagOption thereafter.
set its option_down to (currentModifiers div 524288 mod 2 is 1)
-- 1048576: NSCommandKeyMask/NSEventModifierFlagCommand.
set its command_down to (currentModifiers div 1048576 mod 2 is 1)
-- 131072: NSShiftKeyMask/NSEventModifierFlagShift.
set its shift_down to (currentModifiers div 131072 mod 2 is 1)
-- 262144: NSControlKeyMask/NSEventModifierKeyControl.
set its control_down to (currentModifiers div 262144 mod 2 is 1)
end tell
return modifierKeysDOWN
end modifierKeysPressed
modifierKeysPressed()
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: detecting capslock key down
Well, inelegant is as inelegant does, a matter of subjective aesthetics, something when it comes to programmingan inelegant approach....
I don't bother with; I just attempt to get a job done.
But, then, I have never really bothered about cars: a Lada will get you to Moscow just as will a Merc.
-
I would not doubt that for a moment, but as soon as you leave "planet Apple" that will doyou can detect state of control keys including capslock from applescript
you not a whit of good at all.
Last edited by richmond62 on Mon Jul 12, 2021 5:43 pm, edited 1 time in total.
Re: detecting capslock key down
Interesting, but how is this better than using shiftLockKey to detect the state of capslock?
------
EDIT: the above is a typo/autocorrect: it should read: how is this better than using capsLockKey() to detect the state of capslock?
Last edited by stam on Mon Jul 12, 2021 2:05 pm, edited 2 times in total.
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: detecting capslock key down
?using shiftLockKey to detect the state of capslock?
Surely you would use shiftLockKey on something like a BBC micro that actually has a shift lock key?
ALSO: one should not confuse a shiftLock key for a capsLocks key.
- -
ALSO shiftLock does NOT occur in the LiveCode dictionary.
Re: detecting capslock key down
Well done Richmond... you spotted my typo! Congratsrichmond62 wrote: ↑Mon Jul 12, 2021 10:30 amALSO: one should not confuse a shiftLock key for a capsLocks key.
Good to know you're paying attention...
I of course meant capsLockKey() to detect the state of the capsLock.
Given that we're talking about the capslockkey and capslock and more capslock, it should't really be a surprise this was an error.
Well done on finding yet another picture to post though...
To re-iterate, in case there is any misunderstanding (and lest i give Richmond yet another excuse to post pictures):
I did not mean to type shiftLock! Sorry!
Re: detecting capslock key down
But shiftLock happens.
I miss Hermann
I miss Hermann