Skip to content

Instantly share code, notes, and snippets.

@drobune

drobune/emacs.ahk

Created Jul 22, 2016
Embed
What would you like to do?
Windows10 AutoHotkeyの設定
;================================================================
;auto hot key script for windows
;mac風キーバインド
;================================================================
#InstallKeybdHook
#UseHook
;================================================================
;関数
;================================================================
;----------------------------------------------------------------
;キーバインドを無効にするウィンドウかどうか判断する
; ahk_classはauto hot key付属のAU3_Spy.exeを使用して調べる。
; 引数 なし
; 戻り値 1:キーバインドを無効にするウィンドウ
; 0:キーバインドを有効にするウィンドウ
;---------------------------------------------------------------;-
;is_disable_window()
;{
;gvim
; IfWinActive,ahk_class Vim
; {
; return 1
; }
; ;tera term
; IfWinActive,ahk_class VTWin32
; {
; return 1
; }
; ;vmware player
; IfWinActive,ahk_class VMPlayerFrame
; {
; return 1
; }
; return 0
;}
;----------------------------------------------------------------
;キーを送信する
; キーバインドを無効にするウィンドウでは、送信されたキーをそのまま使用する
; キーバインドを有効にするウィンドウでは、送信されたキーを置き換える
;
; 引数 original_key:キーバインドを無効にするウィンドウの場合、送信するキー
; replace_key:キーバインドを有効にするウィンドウの場合、送信するキー
; 戻り値 なし
;----------------------------------------------------------------
send_key(original_key,replace_key)
{
; if (is_disable_window())
; {
; Send,%original_key%
; return
; }
Send,%replace_key%
return
}
;
;================================================================
;ctrlキーバインド
;================================================================
;----------------------------------------------------------------
;移動系(shiftキーとの同時押し対応)
;ctrl + n : 下
;ctrl + p : 上
;ctrl + f : 右
;ctrl + b : 左
;ctrl + a : Home
;ctrl + e : End
;----------------------------------------------------------------
<^n::send_key("^n","{Down}")
<^+n::send_key("^+n","+{Down}")
<^p::send_key("^p","{Up}")
<^+p::send_key("^+p","+{Up}")
;<^F::send_key("^F","{Right}")
;<^+F::send_key("^+F","+{Right}")
<^b::send_key("^b","{Left}")
<^+b::send_key("^+b","+{Left}")
<^a::send_key("^a","{Home}")
<^+a::send_key("^+a","+{Home}")
;<^e::send_key("^e","{End}")
;<^+e::send_key("^+e","+{End}")
;----------------------------------------------------------------
;編集系
;ctrl + h : BackSpace
;ctrl + d : Delete
;ctrl + m : Enter
;ctrl + k : カーソルから行末まで削除
;----------------------------------------------------------------
<^h::send_key("^h","{BS}")
;<^d::send_key("^d","{Del}")
<^m::send_key("^m","{Return}")
;<^k::send_key("^k","+{End}{Del}")
SetTitleMatchMode, Regex
#IfWinActive, (- Google Chrome)$
^+w::
;do nothing
return
#IfWinActive
$*MButton::
Hotkey, $*MButton Up, MButtonup, off
KeyWait, MButton, T0.2
If ErrorLevel = 1
{
Hotkey, $*MButton Up, MButtonup, on
MouseGetPos, ox, oy
SetTimer, WatchTheMouse, 1
SystemCursor("Toggle")
}
Else
Send {MButton}
return
MButtonup:
Hotkey, $*MButton Up, MButtonup, off
SetTimer, WatchTheMouse, off
SystemCursor("Toggle")
return
WatchTheMouse:
MouseGetPos, nx, ny
dy := ny-oy
dx := nx-ox
If (dx**2 > 0 and dx**2>dy**2) ;edit 4 for sensitivity (changes sensitivity to movement)
{
times := Abs(dy)/1 ;edit 1 for sensitivity (changes frequency of scroll signal)
Loop, %times%
{
If (dx > 0)
Click WheelLeft
Else
Click WheelRight
}
}
If (dy**2 > 0 and dy**2>dx**2) ;edit 0 for sensitivity (changes sensitivity to movement)
{
times := Abs(dy)/1 ;edit 1 for sensitivity (changes frequency of scroll signal)
Loop, %times%
{
If (dy > 0)
Click WheelUp
Else
Click WheelDown
}
}
MouseMove ox, oy
return
SystemCursor(OnOff=1) ; INIT = "I","Init"; OFF = 0,"Off"; TOGGLE = -1,"T","Toggle"; ON = others
{
static AndMask, XorMask, $, h_cursor
,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 ; system cursors
, b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13 ; blank cursors
, h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13 ; handles of default cursors
if (OnOff = "Init" or OnOff = "I" or $ = "") ; init when requested or at first call
{
$ = h ; active default cursors
VarSetCapacity( h_cursor,4444, 1 )
VarSetCapacity( AndMask, 32*4, 0xFF )
VarSetCapacity( XorMask, 32*4, 0 )
system_cursors = 32512,32513,32514,32515,32516,32642,32643,32644,32645,32646,32648,32649,32650
StringSplit c, system_cursors, `,
Loop %c0%
{
h_cursor := DllCall( "LoadCursor", "uint",0, "uint",c%A_Index% )
h%A_Index% := DllCall( "CopyImage", "uint",h_cursor, "uint",2, "int",0, "int",0, "uint",0 )
b%A_Index% := DllCall("CreateCursor","uint",0, "int",0, "int",0
, "int",32, "int",32, "uint",&AndMask, "uint",&XorMask )
}
}
if (OnOff = 0 or OnOff = "Off" or $ = "h" and (OnOff < 0 or OnOff = "Toggle" or OnOff = "T"))
$ = b ; use blank cursors
else
$ = h ; use the saved cursors
Loop %c0%
{
h_cursor := DllCall( "CopyImage", "uint",%$%%A_Index%, "uint",2, "int",0, "int",0, "uint",0 )
DllCall( "SetSystemCursor", "uint",h_cursor, "uint",c%A_Index% )
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment