Last active
July 6, 2022 07:16
-
-
Save rileyJones/5406d7767db1a48bf21cf3fe75122bdc to your computer and use it in GitHub Desktop.
PDMM+; touchpad as touch slider; AHK script
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
USE: | |
This autohotkey script allows the touchpad to operate like a touch slider in Project Diva Megamix+ | |
DISADVANTAGES: | |
This script disables the Left Control key, | |
rebinds scrolling, | |
and will type letters when you move the mouse | |
SETUP: | |
1. Make sure "mouseDelta.ahk" and "TouchSlider.ahk" are in the same folder | |
2. Set "Left Slider" to 'g' and "Right Slider" to 'h' | |
TO ENABLE: | |
1. Run the "TouchSlider.ahk" script | |
2. Press the 'F12' Key; this will press the 'g' or 'h' keys based on how you move the mouse | |
3. Press the 'F1' Key; this will make the mouse slowly move right | |
TO DISABLE | |
1. Press the 'F12' Key; this will make the mouse work like normal | |
2. Either close the window this creates, which will close the script, or close the script directly | |
CREDITS | |
This script is lightly modified from the script available here: | |
https://www.autohotkey.com/boards/viewtopic.php?t=10159 |
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
;https://www.autohotkey.com/boards/viewtopic.php?t=10159 | |
; Instantiate this class and pass it a func name or a Function Object | |
; The specified function will be called with the delta move for the X and Y axes | |
; Normally, there is no windows message "mouse stopped", so one is simulated. | |
; After 10ms of no mouse movement, the callback is called with 0 for X and Y | |
Class MouseDelta { | |
State := 0 | |
__New(callback){ | |
;~ this.TimeoutFn := this.TimeoutFunc.Bind(this) | |
this.MouseMovedFn := this.MouseMoved.Bind(this) | |
this.Callback := callback | |
} | |
Start(){ | |
static DevSize := 8 + A_PtrSize, RIDEV_INPUTSINK := 0x00000100 | |
; Register mouse for WM_INPUT messages. | |
VarSetCapacity(RAWINPUTDEVICE, DevSize) | |
NumPut(1, RAWINPUTDEVICE, 0, "UShort") | |
NumPut(2, RAWINPUTDEVICE, 2, "UShort") | |
NumPut(RIDEV_INPUTSINK, RAWINPUTDEVICE, 4, "Uint") | |
; WM_INPUT needs a hwnd to route to, so get the hwnd of the AHK Gui. | |
; It doesn't matter if the GUI is showing, it still exists | |
Gui +hwndhwnd | |
NumPut(hwnd, RAWINPUTDEVICE, 8, "Uint") | |
this.RAWINPUTDEVICE := RAWINPUTDEVICE | |
DllCall("RegisterRawInputDevices", "Ptr", &RAWINPUTDEVICE, "UInt", 1, "UInt", DevSize ) | |
OnMessage(0x00FF, this.MouseMovedFn) | |
this.State := 1 | |
return this ; allow chaining | |
} | |
Stop(){ | |
static RIDEV_REMOVE := 0x00000001 | |
static DevSize := 8 + A_PtrSize | |
OnMessage(0x00FF, this.MouseMovedFn, 0) | |
RAWINPUTDEVICE := this.RAWINPUTDEVICE | |
NumPut(RIDEV_REMOVE, RAWINPUTDEVICE, 4, "Uint") | |
DllCall("RegisterRawInputDevices", "Ptr", &RAWINPUTDEVICE, "UInt", 1, "UInt", DevSize ) | |
this.State := 0 | |
return this ; allow chaining | |
} | |
SetState(state){ | |
if (state && !this.State) | |
this.Start() | |
else if (!state && this.State) | |
this.Stop() | |
return this ; allow chaining | |
} | |
Delete(){ | |
this.Stop() | |
;~ this.TimeoutFn := "" | |
this.MouseMovedFn := "" | |
} | |
; Called when the mouse moved. | |
; Messages tend to contain small (+/- 1) movements, and happen frequently (~20ms) | |
MouseMoved(wParam, lParam){ | |
Critical | |
; RawInput statics | |
static DeviceSize := 2 * A_PtrSize, iSize := 0, sz := 0, pcbSize:=8+2*A_PtrSize, offsets := {x: (20+A_PtrSize*2), y: (24+A_PtrSize*2)}, uRawInput | |
static axes := {x: 1, y: 2} | |
; Get hDevice from RAWINPUTHEADER to identify which mouse this data came from | |
VarSetCapacity(header, pcbSize, 0) | |
If (!DllCall("GetRawInputData", "UPtr", lParam, "uint", 0x10000005, "UPtr", &header, "Uint*", pcbSize, "Uint", pcbSize) or ErrorLevel) | |
Return 0 | |
ThisMouse := NumGet(header, 8, "UPtr") | |
; Find size of rawinput data - only needs to be run the first time. | |
if (!iSize){ | |
r := DllCall("GetRawInputData", "UInt", lParam, "UInt", 0x10000003, "Ptr", 0, "UInt*", iSize, "UInt", 8 + (A_PtrSize * 2)) | |
VarSetCapacity(uRawInput, iSize) | |
} | |
sz := iSize ; param gets overwritten with # of bytes output, so preserve iSize | |
; Get RawInput data | |
r := DllCall("GetRawInputData", "UInt", lParam, "UInt", 0x10000003, "Ptr", &uRawInput, "UInt*", sz, "UInt", 8 + (A_PtrSize * 2)) | |
x := 0, y := 0 ; Ensure we always report a number for an axis. Needed? | |
x := NumGet(&uRawInput, offsets.x, "Int") | |
y := NumGet(&uRawInput, offsets.y, "Int") | |
this.Callback.(ThisMouse, x, y) | |
;~ ; There is no message for "Stopped", so simulate one | |
;~ fn := this.TimeoutFn | |
;~ SetTimer, % fn, -50 | |
} | |
;~ TimeoutFunc(){ | |
;~ this.Callback.("", 0, 0) | |
;~ } | |
} |
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
;https://www.autohotkey.com/boards/viewtopic.php?t=10159 | |
#include MouseDelta.ahk | |
#SingleInstance,Force | |
Gui, Add, ListBox, w300 h200 hwndhOutput | |
Gui, Add, Text, xm w300 center, Hit F12 to toggle on / off | |
Gui, Show,, Mouse Watcher | |
MacroOn := 0 | |
md := new MouseDelta("MouseEvent") | |
return | |
GuiClose: | |
md.Delete() | |
md := "" | |
ExitApp | |
F12:: | |
MacroOn := !MacroOn | |
md.SetState(MacroOn) | |
return | |
F1:: | |
while(MacroOn) { | |
MouseMove, 1, 0, 100, Relative | |
Sleep, 50 | |
} | |
return | |
; Gets called when mouse moves | |
; x and y are DELTA moves (Amount moved since last message), NOT coordinates. | |
MouseEvent(MouseID, x := 0, y := 0){ | |
global hOutput | |
global gUp | |
global hUp | |
static LastTime := 0 | |
t := A_TickCount | |
if(x > 100) { | |
if(t - LastTime > 250) { | |
gUp := true | |
hUp := true | |
send {g up} | |
send {h up} | |
} | |
return | |
} | |
if( x < 5 and x > -5) { | |
return | |
} | |
static text := "" | |
;t := A_TickCount | |
;if(t - lastTime > 300) { | |
; gUp := true | |
; hUp := true | |
; send {g up} | |
; send {h up} | |
;} | |
text := "x: " x ", y: " y (LastTime ? (", Delta Time: " t - LastTime " ms, MouseID: " MouseID) : "") | |
GuiControl, , % hOutput, % text | |
sendmessage, 0x115, 7, 0,, % "ahk_id " hOutput | |
LastTime := t | |
if( x < 0) { | |
if(gUp) { | |
gUp := false | |
hUp := true | |
send {g down} | |
send {h up} | |
} | |
} else { | |
if(hUp) { | |
hUp := false | |
gUp := true | |
send {h down} | |
send {g up} | |
} | |
} | |
} | |
Wheelup:: | |
if(MacroOn) { | |
global hUp := false | |
global gUp := false | |
send {h down} | |
send {g down} | |
} | |
return | |
Wheeldown:: | |
if(MacroOn) { | |
global hUp := false | |
global gUp := false | |
send {h down} | |
send {g down} | |
} | |
return | |
LControl:: | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment