• 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: Is Keypressed dead forever?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is Keypressed dead forever?


  • Subject: Re: Is Keypressed dead forever?
  • From: Yvan KOENIG <email@hidden>
  • Date: Wed, 30 Nov 2016 11:34:42 +0100

Hello Robert

If you really want to get the state of several modifiers with a single call you may use:

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit" -- for NSEvent


delay 3
set {optionState, controlState, commandState, shiftState} to my checkModifier:{"shift", "command"}
display dialog "optionState = " & optionState & linefeed & "controlState = " & controlState & linefeed & "commandState = " & commandState & linefeed & "shiftState = " & shiftState


on checkModifier:keyList
set theResults to {false, false, false, false}
set theFlag to current application's NSEvent's modifierFlags() as integer
if keyList contains "option" then
set theMask to current application's NSAlternateKeyMask as integer
if ((theFlag div theMask) mod 2) = 0 then
false
else
true
end if
set item 1 of theResults to result
end if
if keyList contains "control" then
set theMask to current application's NSControlKeyMask as integer
if ((theFlag div theMask) mod 2) = 0 then
false
else
true
end if
set item 2 of theResults to result
end if
if keyList contains "command" then
set theMask to current application's NSCommandKeyMask as integer
if ((theFlag div theMask) mod 2) = 0 then
false
else
true
end if
set item 3 of theResults to result
end if
if keyList contains "shift" then
set theMask to current application's NSShiftKeyMask as integer
if ((theFlag div theMask) mod 2) = 0 then
false
else
true
end if
set item 4 of theResults to result
end if
return theResults
end checkModifier:


I wish to add that given your original question I assumed that you wished to get the key pressed, not the modifier ones.
After all, you already asked for - and got - the code testing the modifiers on 2016/09/23.


Yvan KOENIG running Sierra 10.12.1 in French (VALLAURIS, France) mercredi 30 novembre 2016 11:34:38



 _______________________________________________
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: Is Keypressed dead forever?
      • From: Shane Stanley <email@hidden>
    • Re: Is Keypressed dead forever?
      • From: Yvan KOENIG <email@hidden>
References: 
 >Is Keypressed dead forever? (From: Robert Poland <email@hidden>)
 >Re: Is Keypressed dead forever? (From: Yvan KOENIG <email@hidden>)
 >Re: Is Keypressed dead forever? (From: Robert Poland <email@hidden>)
 >Re: Is Keypressed dead forever? (From: Shane Stanley <email@hidden>)
 >Re: Is Keypressed dead forever? (From: Robert Poland <email@hidden>)

  • Prev by Date: Re: what's in a standard library?
  • Next by Date: Re: Is Keypressed dead forever?
  • Previous by thread: Re: Is Keypressed dead forever?
  • Next by thread: Re: Is Keypressed dead forever?
  • Index(es):
    • Date
    • Thread