Opt, Cmd, Shift, Caps key handling

Are you developing tools to extend the LiveCode environment? This is the place to talk about the nuts and bolts of extending our nuts and bolts. If you want to use a LiveCode or third party Environment extension, visit the Using Evironment Extensions forum.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
seaniepie
Posts: 110
Joined: Wed Sep 07, 2011 10:56 am

Opt, Cmd, Shift, Caps key handling

Post by seaniepie » Sun Sep 25, 2016 4:50 pm

Hi all,
I need to make a way to handle messages from Opt, Cmd, Shift and CapsLock key presses without having to wait for other keys to be pressed (which is easy for example using either the optkeydown message or the RawKeyDown message). I had been hoping the Infinite LiveCode project which could have made it possible would have been finished by now but no such luck. Is there any other way that people have made it possible to add in this functionality?

seaniepie
Posts: 110
Joined: Wed Sep 07, 2011 10:56 am

Re: Opt, Cmd, Shift, Caps key handling

Post by seaniepie » Sat Oct 01, 2016 6:39 pm

58 views to date, no takers :roll:

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5344
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Opt, Cmd, Shift, Caps key handling

Post by FourthWorld » Sat Oct 01, 2016 7:10 pm

Polling the shiftkey, optionkey, etc., messages can provide that.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1521
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Opt, Cmd, Shift, Caps key handling

Post by [-hh] » Tue Nov 01, 2016 4:30 am

You may be interested in this note from the dictionary (rawkeyDown)
Cross-platform note: On Mac OS systems, no message is sent when a modifier key (Shift, Option, Control, or Command) is pressed, unless another key is pressed along with the modifier key. Mouse wheels do not send a rawKeyDown message on Mac OS systems>.
shiftLock happens

seaniepie
Posts: 110
Joined: Wed Sep 07, 2011 10:56 am

Re: Opt, Cmd, Shift, Caps key handling

Post by seaniepie » Fri Jan 20, 2017 5:38 pm

Thanks HH, but:
http://stackoverflow.com/questions/9268 ... en-pressed
From the Cocoa event handling guide:
The flagsChanged: method can be useful for detecting the pressing of modifier keys without any other key being pressed simultaneously. For example, if the user presses the Option key by itself, your responder object can detect this in its implementation of flagsChanged
:.
More details here:
https://developer.apple.com/library/con ... vents.html

When Infinite pulls its thumb out of its butt I can push on with this and more. They promised for Summer 2016. !!

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1521
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Opt, Cmd, Shift, Caps key handling

Post by [-hh] » Fri Jan 20, 2017 8:34 pm

Sorry, I was wrong. "MacOS" means in the dictionary the old MacOS 9.
You may try your luck with the following, as Richard said above, works here on MacOS 10.12.

Code: Select all

on idle
   put "option: " & the optionkey &cr& \
         "command: " & the cmdkey &cr& \
         "shift: " & the shiftkey &cr& \
         "capslock: " & the capslockkey &cr& \
         "control: " & the ctrlkey into ks
   put the keysdown &cr& ks into fld 1
end idle
Note.
= Cmdkey and are not distinguishable from keycode in keysdown.
= You may also read the dictionary entry to cmdkey/ctrlkey (cross-platform note).
shiftLock happens

seaniepie
Posts: 110
Joined: Wed Sep 07, 2011 10:56 am

Re: Opt, Cmd, Shift, Caps key handling

Post by seaniepie » Fri Feb 10, 2017 6:38 pm

This was perfect, worked exactly as expected. The 'on idle' helped. Well done, thanks HH

Post Reply

Return to “Extending LiveCode”