• 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: Shane Stanley <email@hidden>
  • Date: Wed, 03 Aug 2011 08:32:39 +1000
  • Thread-topic: Detecting a keydown or key up.

On 3/8/11 7:25 AM, "Luther Fuller" <email@hidden> wrote:

> What would be nice in AppleScript is a function that would return, perhaps, a
> list of names of all keys pressed.
> I could use it in an application with instructions such as ...
> "Launch the application with the option key pressed and you will get ..."
>
> on run
> get keyboardStatus
> if the result contains "option" then
> -- do this
> else
> -- do that
> end if
> end run
>
> Surely there must be something in unix to do this, but I searched a few
> minutes ago and ... nothing!

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:

on run
if checkModifier_(me) then -- "option" key is down
-- do this
else
-- do that
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_


--
Shane Stanley <email@hidden>
'AppleScriptObjC Explored' <www.macosxautomation.com/applescript/apps/>


 _______________________________________________
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>
References: 
 >Re: Detecting a keydown or key up. (From: Luther Fuller <email@hidden>)

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