Skip to content

Instantly share code, notes, and snippets.

@unok
Last active April 21, 2024 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unok/a6226df7b323f17bcc67460e7b2ff384 to your computer and use it in GitHub Desktop.
Save unok/a6226df7b323f17bcc67460e7b2ff384 to your computer and use it in GitHub Desktop.
F20 + key combination
#Requires AutoHotkey v2.0
;-----------------------------------------------------------
; 設定内容
;
; Ctrl-u IME OFF
;
; F20 + ` Escape
; F20 + 1 F1
; F20 + 2 F2
; F20 + 3 F3
; F20 + 4 F4
; F20 + 5 F5
; F20 + 6 F6
; F20 + 7 F7
; F20 + 8 F8
; F20 + 9 F9
; F20 + 10 F10
; F20 + - F11
; F20 + = F12
;
; F20 + n Down
; F20 + p Up
; F20 + h Left
; F20 + l Right
; F20 + f Right
; F20 + b Left
;
; F20 + a Home
; F20 + e End
; F20 + k 末尾まで選択して削除
;
; Alt + F20 + n Scroll Down
; Alt + F20 + p Scroll Up
; Alt + F20 + h Scroll Left
; Alt + F20 + l Scroll Right
;
; Alt + F20 + w Mouse Cursor Up
; Alt + F20 + s Mouse Cursor Down
; Alt + F20 + a Mouse Cursor Left
; Alt + F20 + d Mouse Cursor Right
;
;-----------------------------------------------------------
IME_SET(SetSts, WinTitle := "A") {
hwnd := WinExist(WinTitle)
if (WinActive(WinTitle)) {
ptrSize := !A_PtrSize ? 4 : A_PtrSize
cbSize := 4 + 4 + (PtrSize * 6) + 16
stGTI := Buffer(cbSize, 0)
NumPut("Uint", cbSize, stGTI.Ptr, 0) ; DWORD cbSize;
hwnd := DllCall("GetGUIThreadInfo", "Uint", 0, "Uint", stGTI.Ptr)
? NumGet(stGTI.Ptr, 8 + PtrSize, "Uint") : hwnd
}
return DllCall("SendMessage"
, "UInt", DllCall("imm32\ImmGetDefaultIMEWnd", "Uint", hwnd)
, "UInt", 0x0283 ;Message : WM_IME_CONTROL
, "Int", 0x006 ;wParam : IMC_SETOPENSTATUS
, "Int", SetSts) ;lParam : 0 or 1
}
KeyCombo(key) {
if GetKeyState("Ctrl", "P") && GetKeyState("Shift", "P")
Send "^+" key ""
else if GetKeyState("LWin", "P") && GetKeyState("Shift", "P")
Send "#+" key ""
else if GetKeyState("LWin", "P") && GetKeyState("Ctrl", "P")
Send "^#" key ""
else if GetKeyState("LWin", "P")
Send "#" key ""
else if GetKeyState("Alt", "P")
Send "!" key ""
else if GetKeyState("Shift", "P")
Send "+" key ""
else if GetKeyState("Ctrl", "P")
Send "^" key ""
else
Send key
}
; FキーとCtrlキーの組み合わせを処理する関数
FKeyCtrlCombo(keyNumber, fKeyNumber) {
if GetKeyState("Ctrl", "P") && GetKeyState("Shift", "P")
SendInput "^+{F" fKeyNumber "}"
else if GetKeyState("LWin", "P") && GetKeyState("Shift", "P")
SendInput "#+{F" fKeyNumber "}"
else if GetKeyState("LWin", "P") && GetKeyState("Ctrl", "P")
SendInput "^#{F" fKeyNumber "}"
else if GetKeyState("LWin", "P")
SendInput "#{F" fKeyNumber "}"
else if GetKeyState("Alt", "P")
SendInput "!{F" fKeyNumber "}"
else if GetKeyState("Shift", "P")
SendInput "+{F" fKeyNumber "}"
else if GetKeyState("Ctrl", "P")
SendInput "^{F" fKeyNumber "}"
else
SendInput "{F" fKeyNumber "}"
}
MouseMoveRange := 100
AltKeyCombo(key) {
if GetKeyState("Alt", "P")
if key == "j"
Send "{WheelDown}"
else if key == "k"
Send "{WheelUp}"
else if key == "h"
Send "{WheelLeft}"
else if key == "l"
Send "{WheelRight}"
else if key == "w"
MouseMove(0, -MouseMoveRange, 0, "R")
else if key == "s"
MouseMove(0, MouseMoveRange, 0, "R")
else if key == "a"
MouseMove(-MouseMoveRange, 0, 0, "R")
else if key == "d"
MouseMove(MouseMoveRange, 0, 0, "R")
else
if key == "k"
SendInput "{Shift down}{End}{Del}{Shift up}"
else if key == "h"
KeyCombo("{Backspace}")
else if key == "a"
KeyCombo("{home}")
else if key == "d"
KeyCombo("{Del}")
}
f20 & n:: KeyCombo("{Down}")
f20 & p:: KeyCombo("{Up}")
f20 & f:: KeyCombo("{Right}")
f20 & b:: KeyCombo("{Left}")
; f20 & a:: KeyCombo("{home}")
f20 & e:: KeyCombo("{End}")
; f20 & d:: KeyCombo("{Del}")
f20 & h:: AltKeyCombo("h")
f20 & Backspace:: KeyCombo("{Del}")
f20 & k:: AltKeyCombo("k")
f20 & `:: Send "{Esc}"
f20 & j:: AltKeyCombo("j")
f20 & l:: AltKeyCombo("l")
f20 & w:: AltKeyCombo("w")
f20 & a:: AltKeyCombo("a")
f20 & s:: AltKeyCombo("s")
f20 & d:: AltKeyCombo("d")
f20 & 1:: FKeyCtrlCombo(1, 1)
f20 & 2:: FKeyCtrlCombo(2, 2)
f20 & 3:: FKeyCtrlCombo(3, 3)
f20 & 4:: FKeyCtrlCombo(4, 4)
f20 & 5:: FKeyCtrlCombo(5, 5)
f20 & 6:: FKeyCtrlCombo(6, 6)
f20 & 7:: FKeyCtrlCombo(7, 7)
f20 & 8:: FKeyCtrlCombo(8, 8)
f20 & 9:: FKeyCtrlCombo(9, 9)
f20 & 0:: FKeyCtrlCombo(0, 10)
f20 & -:: FKeyCtrlCombo("-", 11)
f20 & =:: FKeyCtrlCombo("=", 12)
f20 & u:: IME_SET(0)
^u:: IME_SET(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment