2012-12-11 18 views
2

我討厭這個事實,我必須使用alt鍵將cmd + tab切換到隱藏窗口。 我知道有應用程序(如witch)取代了cmd + tab函數,但我喜歡當前的界面,我不想改變它。除此之外,我只是想建立蘋果腳本吧:)蘋果腳本調用alt keypress on cmd + tap keypress切換到隱藏窗口而沒有物理按壓alt

所以這裏就是我想創造:

當我按下cmd+tap - >的keydown alt

後來,當我再放開cmd它應該發佈alt密鑰。

結果將是當我切換到'隱藏'窗口時,我再也不必再次按alt鍵。很像其他操作系統。

但它看起來對我來說,所有的蘋果腳本開始tell application

回答

3

它不是通過更多鈔票AppleScript中用戶檢測按鍵。你可以通過編程按鍵。要解決按住某個按鍵的問題,請使用「按鍵」命令並在需要釋放時發出「按鍵」命令。這將適用於任何應用程序。這是一個例子。

tell application "KeyboardViewer" to activate 
tell application "System Events" 
    try --don't even consider not using a try block because down keys can get stuck! 
     key down control 
     delay 1 
     key down shift 
     delay 1 
     key down option 
     delay 1 
     key down command 
     delay 1 
     key up control 
     delay 1 
     key up shift 
     delay 1 
     key up option 
     delay 1 
     key up command 
     delay 1 
     key down {control, shift, option, command} 
     delay 1 
     key up {control, shift, option, command} 
    on error --logging out is the only other way to unstick these 
     key up {control, shift, option, command} 
    end try 
end tell 
tell application "KeyboardViewer" to quit 

注意:如果您想按順序按下並釋放某些按鍵,也可以使用「keystroke」命令。例如要按命令,您可以執行以下操作:

tell application "System Events" 
    keystroke "s" using command down 
end tell 
+0

感謝您的回答,我會明天嘗試並接受此答案是否有效。看起來非常合乎邏輯,但我現在要走了。 – FLY

+0

我收到錯誤KeyboardViewer找不到 – FLY

+0

試試這個在它的地方。我在10.8上,但在早期版本中,它被稱爲... KeyboardViewerServer.app。 – regulus6633