Page 1 of 1

keysDown function works across applications

Posted: Thu Dec 22, 2016 8:31 pm
by dunbarx
This came up in a recent thread on the use list.

The keysDown function is "read" in a running handler by LC even if one is, say, typing in another application entirely. This is not the case, for example, if one wanted to trap the rawKeyDown message from another app. It is not sent in LC, and I am not surprised. But I am surprised (and a bit impressed) that the function works. How do it know?

Any other gadgetry that LC seems to notice even when it is not in front?

Craig

Re: keysDown function works across applications

Posted: Thu Dec 22, 2016 10:21 pm
by [-hh]
Hi Craig.


Other gettable system events are:
Is the shiftkey (the optionkey, the cmdkey, the ctrlkey) down/up.
Cmdkey and optionkey are at least on MacOS not distinguishable by keysdown().

MouseEvents.

Code: Select all

on idle
   put (mouse(1),mouse(2),mouse(3),mouse(4),the screenMouseLoc) into fld 1
end idle
This is of course, just as with keysdown(), only working if the frontmost app passes these system events.
For example LC doesn't pass a rightClick in the scriptEditor (and you are able to block most event passing in your app).

mouse(2) is the state of the 'middle' mousebutton which is often the mousewheeel button.
I use mostly this button and mouse movements for scrolling in Safari/Firefox, the wheel doesn't scroll in this case.
For catching scrollwheel events one could use (where available) a javascript handler that sends in turn a system event that LC can catch.

Hermann

Re: keysDown function works across applications

Posted: Thu Dec 22, 2016 11:28 pm
by dunbarx
Hermann.

Good to know. So we have a bunch of stuff that works for me in the finder, Safari, TextEdit, Excel, Word, and maybe everywhere. In a button script, with a field:

Code: Select all

on mouseUp
   put "" into fld 1
   repeat until the commandKey is down and the optionKey is down
      wait 5 with messages
      put the keysDown into line 1 of  fld 1
      put the screenmouseloc into line 2 of fld 1
      put mouse() into line 3 of fld 1
      if the optionKey is down then put "Option" into line 4 of fld 1
      if the controlKey is down then put "Control" into line 4 of fld 1
      if the shiftKey is down then put "Shift" into line 4 of fld 1
      if the capsLockKey is down then put "Caps" into line 4 of fld 1
      if the commandKey is down then put "Command" into line 4 of fld 1
      if the commandKey is down and the optionKey is down then
         put "Done" into line 4 of fld 1
         exit to top
      end if
   end repeat
end mouseUp  
Click the button, move to another app. All of these can be read. It is true that the keysDown function does not distinguish commandKey and option key. But the key functions themselves do.

The capsLock key sticks, of course, so you have to release it. All are functions except for "screenMouseLoc", which is a property. The holy grail would be to have a message invoked from the cold.

Craig