天天看點

使用AHK減少滑鼠和方向鍵的使用頻率,高效編輯

autohotkey是一款熱鍵腳本語言,網上相關的介紹很多,我這不多介紹。一般敲多的碼的人,對方向鍵、鍵盤和滑鼠之間來回移動都會覺的是一件很麻煩的事,使用vim的除外,是以我這在這裡介紹使autohot實作滑鼠與方向鍵的功能。

一般來說平時capslock鍵和scrllLock 這兩個鍵使用的頻率非常低,我們可以将caplock設為和ctl、alt、win一樣的功能鍵,但是使用capslock這個設定會有出現大小寫切換的問題,使用ahk這個軟體來換鍵并不是一個好的解決方案,是以我還要用到另一個改鍵軟體 KeyTweak。KeyTweakn改鍵原理是修改系統資料庫,比ahk更為徹底,我将caplock和scrllLock相換一下,以後大小切換就是scrllLock了(我平時都是按shift的)。

使用AHK減少滑鼠和方向鍵的使用頻率,高效編輯

下面開始在ahk中編輯。

滑鼠功能

這部分代碼來自http://www.ahk8.com/,年代久遠原作者記記是誰了。。
           
SetScrollLockState, AlwaysOff;禁用SetScrollLockState
#SingleInstance
count = 
JoyMultiplier = 
JoyThreshold = 
JoyThresholdUpper :=  + JoyThreshold
JoyThresholdLower :=  - JoyThreshold
YAxisMultiplier = -
SetTimer, WatchKeyboard, 

Hotkey, F1, ButtonLeft ;F1模拟左鍵
Hotkey, F2, ButtonRight;F2模拟右鍵
Hotkey, up, empty
Hotkey, down, empty
Hotkey, left, empty
Hotkey, right, empty
Return

ScrollLock & F1:: ;開啟滑鼠功能
SetTimer, WatchKeyboard, 
Hotkey, F1, On
Hotkey, F2, On
Hotkey, up, On
Hotkey, down, On
Hotkey, left, On
Hotkey, right, On
Return

ScrollLock & F2::;關閉滑鼠功能
SetTimer, WatchKeyboard, Off
Hotkey, F1, Off
Hotkey, F2, Off
Hotkey, up, Off
Hotkey, down, Off
Hotkey, left, Off
Hotkey, right, Off
Return

empty:
Return
WatchKeyboard:
MouseNeedsToBeMoved := false  ; Set default.
JoyMultiplier+=
SetFormat, float, 
up:=GetKeyState("Up","p")
down:=GetKeyState("Down","p")
Left:=GetKeyState("Left","p")
right:=GetKeyState("Right","p")
if(Right)
{
    MouseNeedsToBeMoved := true
    DeltaX := 
}
else if(Left)
{
    MouseNeedsToBeMoved := true
    DeltaX := -
}
else
    DeltaX = 
if (up)
{
    MouseNeedsToBeMoved := true
    DeltaY := 
}
else if (Down)
{
    MouseNeedsToBeMoved := true
    DeltaY := -
}
else
    DeltaY = 
if MouseNeedsToBeMoved
{
    SetMouseDelay, -  ; Makes movement smoother.
    MouseMove, DeltaX * JoyMultiplier, DeltaY * JoyMultiplier * YAxisMultiplier, , R
}
Else
count++
If(count>){
JoyMultiplier = 
count=
}
return

ButtonLeft:
SetMouseDelay, -  ; Makes movement smoother.
MouseClick, left,,, , , D  ; Hold down the left mouse button.
SetTimer, WaitForLeftButtonUp, 
return

ButtonRight:
SetMouseDelay, -  ; Makes movement smoother.
MouseClick, right,,, , , D  ; Hold down the right mouse button.
SetTimer, WaitForRightButtonUp, 
return


WaitForLeftButtonUp:;使用支援滑鼠手勢
if GetKeyState("F1")
    return  ; The button is still, down, so keep waiting.
; Otherwise, the button has been released.
SetTimer, WaitForLeftButtonUp, off
SetMouseDelay, -  ; Makes movement smoother.
MouseClick, left,,, , , U  ; Release the mouse button.
return

WaitForRightButtonUp:
if GetKeyState("F2")
    return  ; The button is still, down, so keep waiting.
; Otherwise, the button has been released.
SetTimer, WaitForRightButtonUp, off
MouseClick, right,,, , , U  ; Release the mouse button.
return
;;endmouse
           

方向鍵與其它光标的功能:

按我的設定上下左右分别為caps+i/j/k/l/j;home,end,delete,pgup,pgdn為caps+h/n/o/[/];
           
;scroll事件
ScrollLock & [::send,{WheelUp}
ScrollLock & ]::send,{WheelDown}
; move left
ScrollLock & j::
if GetKeyState("LShift", "P")
    send, +{Left}
else if GetKeyState("LAlt", "P")
    send,^{left}
else
    send, {Left}
Return
; move right
ScrollLock & l::
if GetKeyState("LShift", "P")
    send, +{right}
else if GetKeyState("LAlt", "P")
    send,^{right}
else
    send, {right}
Return
; move up
ScrollLock & i::
if GetKeyState("LShift", "P")
    send, +{up}
else if GetKeyState("LAlt", "P")
    send,^!{up}
else if GetKeyState("LControl", "P")
    send,^+{up}
else
    send, {up}
Return
; move down
ScrollLock & k::
if GetKeyState("LShift", "P")
    send, +{down}
else if GetKeyState("LAlt", "P")
    send,^!{down}
else if GetKeyState("LControl", "P")
    send,^+{down}
else
    send, {down}
Return
;home
ScrollLock & h::
if GetKeyState("LShift", "P")
    send, +{home}
else
    send, {home}
Return
; end
ScrollLock & n::
if GetKeyState("LShift", "P")
    send, +{end}
else
    send, {end}
Return
;delelte
ScrollLock & o::send,{delete}
           

拾色器

利用ahk設定的拾色器非常友善,這裡設定的快揵是alt+win+c

!#c::
    MouseGetPos, mouseX, mouseY
    PixelGetColor, color, %mouseX%, %mouseY%, RGB
    StringRight color,color,
    clipboard = #%color%
    tooltip,color is %color%
    sleep 
    tooltip,
return
           

剪切闆

系統自帶的剪切闆隻能一起複制與粘貼,下面的剪切闆支援最多30次copy,熱鍵如下:

  1. ;win+0:清空 ;
  2. ctrl+c:複制 ;
  3. win+v:依次粘貼 ;
  4. win+]:依次粘貼,但順序相反
handleClip(action)
{
global static AddNextNum
global static GetNextNum
global static HighestNum
global static getprevnum
global static highest1
global static ClipArray
global static ClipArray1
global static ClipArray2
global static ClipArray3
global static ClipArray4
global static ClipArray5
global static ClipArray6
global static ClipArray7
global static ClipArray8
global static ClipArray9
global static ClipArray10
global static ClipArray11
global static ClipArray12
global static ClipArray13
global static ClipArray14
global static ClipArray15
global static ClipArray16
global static ClipArray17
global static ClipArray18
global static ClipArray19
global static ClipArray20
global static ClipArray21
global static ClipArray22
global static ClipArray23
global static ClipArray24
global static ClipArray25
global static ClipArray26
global static ClipArray27
global static ClipArray28
global static ClipArray29
global static ClipArray30

if (action = "save")
{
if (AddNextNum < )
{
AddNextNum +=  ;
}
else
{
AddNextNum :=  ;
}


if (HighestNum < )
{
HighestNum +=  ;
}

GetNextNum := AddNextNum ;
ClipArray%AddNextNum% := Clipboard
highest1 := highestnum + 
getprevnum := 

}
else if ((action = "get") OR (action = "roll"))
{
if (GetNextNum != )
{
if (action = "roll")
{
Send, ^z
}
Clipboard := ClipArray%GetNextNum%
if (GetNextNum > )
{
GetNextNum -=  ;
getprevnum++
}
else
{
getprevnum := 
GetNextNum := HighestNum

}
Send, ^v
}
}
else if (action = "get-reverse")
{
if (GetNextNum != )
{

Clipboard := ClipArray%getprevnum%
if (GetNextNum > )
{
GetNextNum -=  ;
getprevnum++
}
else
{
getprevnum := 
GetNextNum := HighestNum

}
Send, ^v
}
}


else if (action = "rollforward")
{
if (GetNextNum != )
{
Send, ^z
if (GetNextNum < HighestNum)
{
GetNextNum +=  ;
}
else
{
GetNextNum := 
}
Clipboard := ClipArray%GetNextNum%
Send, ^v
}
}
else if (action = "clear")
{

GetNextNum := 
AddNextNum := 
HighestNum := 
getprevnum := 
}
}

#0::
handleClip("clear")
return

^c::
suspend on
Send, ^c
suspend off
handleClip("save")

return

#v::
    handleClip("get-reverse")
return

#]::
    handleClip("get")
return
; #\::
;   handleClip("roll")
;   ToolTip,
;   sleep 
;   tooltip,
; return
#/::
    clipboard =
return

#^\::
    handleClip("rollforward")
return
; end 剪切闆