diff --git a/README.md b/README.md index 9eaf92b..c7643e3 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ Control the cursor with your hand staying on the keyboard's homerow, even if you Inspired by [rvaiya/warpd](https://github.com/rvaiya/warpd). ## Inertia Mode -![image](https://user-images.githubusercontent.com/98432183/197324047-3de42601-3606-4f05-92a4-6645897085fb.png) +![image](https://user-images.githubusercontent.com/98432183/197381484-b4e669f0-c5bd-42af-a469-f21f5191a6a3.png) -1. Press `Shift` `CapsLk` `C` to activate inertia mode. You'll see your main cursor switched to a crosshair. -2. Use `I`/`J`/`K`/`L` to move the cursor. Hold `Shift` to brake for more precise movement, hold `Space` or `CapsLk` to scroll vertically/horizontally. +1. Press `CapsLk` `C` or `LShift` `RShift` `C` to activate inertia mode. You'll see your main cursor switched to a crosshair. +2. Use `I`/`J`/`K`/`L` to move the cursor. Hold `S` to brake for more precise movement, hold `Space` to scroll vertically/horizontally. 3. Press `F`/`E`/`R` to left/right/middle click at the cursor position. 4. Press `Esc` to quit mode. @@ -16,7 +16,7 @@ Inspired by [rvaiya/warpd](https://github.com/rvaiya/warpd). ## Grid Mode ![image](https://user-images.githubusercontent.com/98432183/197323322-09607efb-c940-4add-95e8-660c94c18306.png) -1. Press `Shift` `CapsLk` `G` to activate overlay. You'll see your main cursor switched to a crosshair, and a thin grey border surrounding your screen. +1. Press `CapsLk` `G` or `LShift` `RShift` `G` to activate overlay. You'll see your main cursor switched to a crosshair, and a thin grey border surrounding your screen. 2. Press `I`/`J`/`K`/`L` to bisect the warp region and move your cursor to its center. 3. Press `F`/`E`/`R` to left/right/middle click at the cursor position. 4. Press `Esc` to quit mode. diff --git a/TPMouse.au3 b/TPMouse.au3 index fb8b77c..d06fb4d 100644 --- a/TPMouse.au3 +++ b/TPMouse.au3 @@ -1,4 +1,5 @@ #OnAutoItStartRegister SetProcessDPIAware +#include 'keybinds.au3' _Singleton('TPMouse',0) Opt('GUICloseOnESC',False) Opt('TrayMenuMode',3) @@ -53,6 +54,7 @@ Func SetRawinput($hWnd, $enable) EndFunc Func ProcessKeypress($struct) + Local Static $_ = SingletonKeybinds, $sks=SingletonKeyState If $struct.VKey>0 and $struct.VKey<256 Then SingletonKeyState($struct.VKey,$struct.MakeCode,$struct.Flags) Switch $struct.VKey Case 0x1B ; esc @@ -65,7 +67,7 @@ Func ProcessKeypress($struct) EndIf Case 0x47 ; G If BitAnd(0x0001,$struct.Flags) Then - If SingletonKeyState(0x10) And SingletonKeyState(0x14) Then ; Shift CapsLk G + If $sks(0x14) Or ($sks(0xA0) And $sks(0xA1)) Then ; CapsLk+G or LShift+RShift+G If SingletonInertia() Then SingletonInertia('deactivate') SingletonOverlay('activate') DllCall($user32, "bool", "SetSystemCursor", "handle", CopyIcon($hCursors[2]), "dword", 32512) @@ -75,7 +77,7 @@ Func ProcessKeypress($struct) EndIf Case 0x43 ; C If BitAnd(0x0001,$struct.Flags) Then - If SingletonKeyState(0x10) And SingletonKeyState(0x14) Then ; Shift CapsLk C + If $sks(0x14) Or ($sks(0xA0) And $sks(0xA1)) Then ; CapsLk+C or LShift+RShift+C If SingletonOverlay() Then SingletonOverlay('deactivate') SingletonInertia('activate') DllCall($user32, "bool", "SetSystemCursor", "handle", CopyIcon($hCursors[1]), "dword", 32512) @@ -83,23 +85,23 @@ Func ProcessKeypress($struct) TraySetToolTip('TPMouse - Inertia') EndIf EndIf - Case 0x49 ; I + Case $_('up') If BitAnd(0x0001,$struct.Flags) Then SingletonOverlay('I') - Case 0x4A ; J + Case $_('left') If BitAnd(0x0001,$struct.Flags) Then SingletonOverlay('J') - Case 0x4B ; K + Case $_('down') If BitAnd(0x0001,$struct.Flags) Then SingletonOverlay('K') - Case 0x4C ; L + Case $_('right') If BitAnd(0x0001,$struct.Flags) Then SingletonOverlay('L') - Case 0x46 ; F + Case $_('mb1') SingletonMoupress('mb1',Not BitAnd(0x0001,$struct.Flags)) - Case 0x45 ; E + Case $_('mb2') SingletonMoupress('mb2',Not BitAnd(0x0001,$struct.Flags)) - Case 0x52 ; R + Case $_('mb3') SingletonMoupress('mb3',Not BitAnd(0x0001,$struct.Flags)) - Case 0x10 ; shift + Case $_('brake') If BitAnd(1,$struct.Flags) Then SingletonInertia('clip',15) - Case 0x14, 0x20 ; capslk or space + Case $_('scroll') SingletonInertia('lock',Not BitAnd(0x0001,$struct.Flags)) EndSwitch EndFunc @@ -158,6 +160,7 @@ Func SingletonMoupress($msg=null,$arg=null) EndFunc Func SingletonInertia($msg=null,$arg=null) + Local Static $_=SingletonKeybinds, $sks=SingletonKeyState Local Static $lastTime = TimerInit(), $self = DllStructCreate('bool active;bool lock;bool up;bool down;bool left;bool right;bool brake;float rx;float ry;float vx;float vy;float vmax;float mu') With $self Switch $msg @@ -212,11 +215,11 @@ Func SingletonInertia($msg=null,$arg=null) .ry = $dy-Round($dy) .vx = ($vx*$vx+$vy*$vy<1?0:$vx) .vy = ($vx*$vx+$vy*$vy<1?0:$vy) - .up = SingletonKeyState(0x49) - .left = SingletonKeyState(0x4A) - .down = SingletonKeyState(0x4B) - .right = SingletonKeyState(0x4C) - .brake = SingletonKeyState(0x10) + .up = $sks($_('up')) + .left = $sks($_('left')) + .down = $sks($_('down')) + .right = $sks($_('right')) + .brake = $sks($_('brake')) Local $cur=GetCursorPos() SingletonInertia('clip', 1*($cur.x=0) + 2*($cur.x=@DesktopWidth-1) + 4*($cur.y=0) + 8*($cur.y=@DesktopHeight-1)) EndIf @@ -483,81 +486,3 @@ Func _Singleton($sOccurrenceName, $iFlag = 0) EndIf Return $aHandle[0] EndFunc ;==>_Singleton - -Func EnableHotKeys() - HotKeySet('i',i) - HotKeySet('j',j) - HotKeySet('k',k) - HotKeySet('l',l) - HotKeySet('f',f) - HotKeySet('e',e) - HotKeySet('r',r) - HotKeySet('{space}',space) - HotKeySet('+i',i) - HotKeySet('+j',j) - HotKeySet('+k',k) - HotKeySet('+l',l) - HotKeySet('+f',f) - HotKeySet('+e',e) - HotKeySet('+r',r) - HotKeySet('+{space}',space) -EndFunc -Func DisableHotKeys() - HotKeySet('{space}') - HotKeySet('i') - HotKeySet('j') - HotKeySet('k') - HotKeySet('l') - HotKeySet('f') - HotKeySet('e') - HotKeySet('r') - HotKeySet('{space}') - HotKeySet('+i') - HotKeySet('+j') - HotKeySet('+k') - HotKeySet('+l') - HotKeySet('+f') - HotKeySet('+e') - HotKeySet('+r') - HotKeySet('+{space}') -EndFunc -func space() - Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') - $struct.Vkey = 0x20 - ProcessKeypress($struct) -endfunc -func i() - Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') - $struct.Vkey = 0x49 - ProcessKeypress($struct) -endfunc -func j() - Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') - $struct.Vkey = 0x4A - ProcessKeypress($struct) -endfunc -func k() - Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') - $struct.Vkey = 0x4B - ProcessKeypress($struct) -endfunc -func l() - Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') - $struct.Vkey = 0x4C - ProcessKeypress($struct) -endfunc -func f() - Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') - $struct.Vkey = 0x46 - ProcessKeypress($struct) -endfunc -func e() - Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') - $struct.Vkey = 0x45 - ProcessKeypress($struct) -endfunc -func r() - Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') - $struct.Vkey = 0x52 - ProcessKeypress($struct) -endfunc diff --git a/keybinds.au3 b/keybinds.au3 new file mode 100644 index 0000000..c992d99 --- /dev/null +++ b/keybinds.au3 @@ -0,0 +1,118 @@ +Func EnableHotKeys() + Local Static $_ = SingletonKeybinds, $arr = ['up','left','down','right','mb1','mb2','mb3','brake','scroll'] + For $cmd in $arr + HotKeySet( $_($cmd,1) , $_($cmd,2) ) + HotKeySet( '+' & $_($cmd,1) , $_($cmd,2) ) + Next +EndFunc +Func DisableHotKeys() + Local Static $_ = SingletonKeybinds, $arr = ['up','left','down','right','mb1','mb2','mb3','brake','scroll'] + For $cmd in $arr + HotKeySet( $_($cmd,1) ) + HotKeySet( '+' & $_($cmd,1) ) + Next +EndFunc +Func SingletonKeybinds($action, $mode=0) + ; mode 0 returns vkey, mode 1 returns hotkey, mode 2 returns function + Switch $action + Case 'up' + If $mode Then + Return ( $mode=1 ? '{i}' : callback_i ) + Else + Return 0x49 + EndIf + Case 'left' + If $mode Then + Return ( $mode=1 ? '{j}' : callback_j ) + Else + Return 0x4A + EndIf + Case 'down' + If $mode Then + Return ( $mode=1 ? '{k}' : callback_k ) + Else + Return 0x4B + EndIf + Case 'right' + If $mode Then + Return ( $mode=1 ? '{l}' : callback_l ) + Else + Return 0x4C + EndIf + Case 'mb1' + If $mode Then + Return ( $mode=1 ? '{f}' : callback_f ) + Else + Return 0x46 + EndIf + Case 'mb2' + If $mode Then + Return ( $mode=1 ? '{e}' : callback_e ) + Else + Return 0x45 + EndIf + Case 'mb3' + If $mode Then + Return ( $mode=1 ? '{r}' : callback_r ) + Else + Return 0x52 + EndIf + Case 'brake' + If $mode Then + Return ( $mode=1 ? '{s}' : callback_s ) + Else + Return 0x53 + EndIf + Case 'scroll' + If $mode Then + Return ( $mode=1 ? '{space}' : callback_space ) + Else + Return 0x20 + EndIf + EndSwitch +EndFunc +Func callback_i() + Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') + $struct.Vkey = 0x49 + ProcessKeypress($struct) +EndFunc +Func callback_j() + Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') + $struct.Vkey = 0x4A + ProcessKeypress($struct) +EndFunc +Func callback_k() + Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') + $struct.Vkey = 0x4B + ProcessKeypress($struct) +EndFunc +Func callback_l() + Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') + $struct.Vkey = 0x4C + ProcessKeypress($struct) +EndFunc +Func callback_f() + Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') + $struct.Vkey = 0x46 + ProcessKeypress($struct) +EndFunc +Func callback_e() + Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') + $struct.Vkey = 0x45 + ProcessKeypress($struct) +EndFunc +Func callback_r() + Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') + $struct.Vkey = 0x52 + ProcessKeypress($struct) +EndFunc +Func callback_s() + Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') + $struct.Vkey = 0x53 + ProcessKeypress($struct) +EndFunc +Func callback_space() + Local $struct = DllStructCreate('ushort MakeCode;ushort Flags;ushort VKey;') + $struct.Vkey = 0x20 + ProcessKeypress($struct) +EndFunc