• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Detecting a keydown or key up.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting a keydown or key up.


  • Subject: Re: Detecting a keydown or key up.
  • From: Luther Fuller <email@hidden>
  • Date: Tue, 02 Aug 2011 18:35:23 -0500

On Aug 2, 2011, at 5:32 PM, Shane Stanley wrote:

So open AppleScript Editor in Lion and choose File -> New From Template ->
Cocoa-AppleScript Applet.app. Include the handler Alex posted above, so your
script is like this:

So I did that ...

on run
if checkModifier_(me) then -- "option" key is down
display dialog "Option key down"
else
display dialog "Option key up"
end if
end run

on checkModifier_(sender)
set theMask to current application's NSAlternateKeyMask as integer
set theFlag to current application's NSEvent's modifierFlags() as integer
return ((theFlag div theMask) mod 2) as boolean
end checkModifier_

and it works! ... but it won't quit. I have to quit manually before I can run it again.
(I must be missing something new in Lion AppleScript)
And it also works in 10.6.8.

And, I suspect that if I look at the output of NSAlternateKeyMask and NSEvent's modifierFlags I will see something that will let me include 'shift', 'command', 'control' &c. (?)

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Detecting a keydown or key up.
      • From: Luther Fuller <email@hidden>
    • Re: Detecting a keydown or key up.
      • From: Shane Stanley <email@hidden>
References: 
 >Re: Detecting a keydown or key up. (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: AppleScript controlling Xcode 4.01
  • Next by Date: Re: Detecting a keydown or key up.
  • Previous by thread: Re: Detecting a keydown or key up.
  • Next by thread: Re: Detecting a keydown or key up.
  • Index(es):
    • Date
    • Thread