Created
February 2, 2009 09:14
-
-
Save azu/56848 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
適当な名前.ahk で保存(要AutoHotKey) | |
**/ | |
#SingleInstance | |
; (サンプル) Deleteキー長押し時に"Backspace"キーを発行 | |
InitLongKeyPress("Delete", 500, "key", "Backspace") | |
return | |
* 指定のキーの長押しの設定を行う。 | |
* "Hotkey"コマンドでのキー設定なので、"Hotkey, IfWinExist,..."等が利用可能(なはず) | |
* | |
* @param keyName - 設定対象キー名 | |
* @param delay - 長押しと判断する経過時間(ms) | |
* @param actType - key:キー押下発行, sub:関数呼び出し, その他:何もしない | |
* @param action - 長押ししたときに動作するサブルーチン名 or キー名 | |
* | |
* サブルーチン "LongKeyPressStart", "LongKeyPressEnd"に依存 | |
*/ | |
InitLongKeyPress(keyName, delay, actType, action) { | |
global | |
longKeyPressDelay_%keyName% := delay | |
longKeyPressActType_%keyName% := actType | |
longKeyPressAction_%keyName% := action | |
Hotkey, %keyName%, LongKeyPressStart, On | |
Hotkey, %keyName% up, LongKeyPressEnd, On | |
} | |
; キー押下時のシステム時刻をキー毎に記録する | |
LongKeyPressStart: | |
if (!(longKeyPressKeyDown_%A_ThisHotkey% > 0)) { | |
longKeyPressKeyDown_%A_ThisHotkey% := A_TickCount | |
} | |
return | |
; キー押下中の経過時間を取得し、設定に基づき動作する。(キー名は" up"を取り除く) | |
LongKeyPressEnd: | |
StringTrimRight, longKeyPressKeyName, A_ThisHotkey, 3 | |
if (A_TickCount - longKeyPressKeyDown_%longKeyPressKeyName% > longKeyPressDelay_%longKeyPressKeyName%) { | |
longKeyPressAction := longKeyPressAction_%longKeyPressKeyName% | |
longKeyPressActType := longKeyPressActType_%longKeyPressKeyName% | |
if (longKeyPressActType = "key") | |
Send, {%longKeyPressAction%} | |
else if (longKeyPressActType = "sub") | |
Gosub, %longKeyPressAction% | |
} | |
else | |
Send, {%longKeyPressKeyName%} | |
longKeyPressKeyDown_%longKeyPressKeyName% := -1 | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment