-
Notifications
You must be signed in to change notification settings - Fork 11
/
DisableTouchPad.ahk
94 lines (81 loc) · 2.4 KB
/
DisableTouchPad.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
; v1.0 2010-02-23 Original Release
; v1.1 2010-02-25 Added user configuration section
; Added option to block mouse clicks
; Added option to omit blocking for shift, ctrl, alt, win keys
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;user configuration
DisableTime := 500 ;in milliseconds
BlockMouseMove := True
BlockLeftClick := True
BlockMiddleClick := True
BlockRightClick := True
AllowShift := True
AllowCtrl := True
AllowAlt := True
AllowWin :=True
;keyboard hook code credit: http://www.autohotkey.com/forum/post-127490.html#127490
#Persistent
OnExit, Unhook
;initialize
hHookKeybd := SetWindowsHookEx(WH_KEYBOARD_LL := 13, RegisterCallback("Keyboard", "Fast"))
Hotkey, LButton, DoNothing, Off
Hotkey, MButton, DoNothing, Off
Hotkey, RButton, DoNothing, Off
Return
DisableTrackpad:
ShiftActive := AllowShift && GetKeyState("Shift")
CtrlActive := AllowCtrl && GetKeyState("Ctrl")
AltActive := AllowAlt && GetKeyState("Alt")
LWinActive := AllowWin && GetKeyState("LWin")
RWinActive := AllowWin && GetKeyState("RWin")
if (!ShiftActive && !CtrlActive && !AltActive && !LWinActive && !RWinActive)
{
if (BlockMouseMove)
BlockInput, MouseMove
if (BlockLeftClick)
Hotkey, LButton, DoNothing, On
if (BlockMiddleClick)
Hotkey, MButton, DoNothing, On
if (BlockLeftClick)
Hotkey, RButton, DoNothing, On
}
Return
ReenableTrackpad:
if (BlockMouseMove)
BlockInput, MouseMoveOff
if (BlockLeftClick)
Hotkey, LButton, Off
if (BlockMiddleClick)
Hotkey, MButton, Off
if (BlockLeftClick)
Hotkey, RButton, Off
Return
DoNothing:
Return
Unhook:
UnhookWindowsHookEx(hHookKeybd)
ExitApp
Keyboard(nCode, wParam, lParam)
{
Critical
If !nCode
{
Gosub, DisableTrackpad
SetTimer, ReenableTrackpad, %DisableTime%
}
Return CallNextHookEx(nCode, wParam, lParam)
}
SetWindowsHookEx(idHook, pfn)
{
Return DllCall("SetWindowsHookEx", "int", idHook, "Uint", pfn, "Uint", DllCall("GetModuleHandle", "Uint", 0), "Uint", 0)
}
UnhookWindowsHookEx(hHook)
{
Return DllCall("UnhookWindowsHookEx", "Uint", hHook)
}
CallNextHookEx(nCode, wParam, lParam, hHook = 0)
{
Return DllCall("CallNextHookEx", "Uint", hHook, "int", nCode, "Uint", wParam, "Uint", lParam)
}