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
local cfg = UI.Schema({
up = UI.Keybind("Kp8", { label = "Up", tab = "Keys" }),
down = UI.Keybind("Kp2", { label = "Down", tab = "Keys" }),
left = UI.Keybind("Kp4", { label = "Left", tab = "Keys" }),
right = UI.Keybind("Kp6", { label = "Right", tab = "Keys" }),
upLeft = UI.Keybind("Kp7", { label = "Up and left", tab = "Keys" }),
upRight = UI.Keybind("Kp9", { label = "Up and right", tab = "Keys" }),
downLeft = UI.Keybind("Kp1", { label = "Down and left", tab = "Keys" }),
downRight = UI.Keybind("Kp3", { label = "Down and right", tab = "Keys" }),
click = UI.Keybind("Kp5", { label = "Click", tab = "Keys" }),
rightClick = UI.Keybind("KpPlus", { label = "Right click", tab = "Keys" }),
middleClick = UI.Keybind("KpEnter", { label = "Middle click", tab = "Keys" }),
drag = UI.Keybind("Kp0", { label = "Drag lock on or off", tab = "Keys" }),
slow = UI.Slider(2, { min = 1, max = 10, suffix = " px", label = "Start speed" }),
fast = UI.Slider(18, { min = 4, max = 60, suffix = " px", label = "Top speed" }),
ramp = UI.Slider(700, {
min = 0,
max = 2000,
suffix = " ms",
label = "Time to top speed",
}),
})
local DIRS = {
[cfg.up] = { 0, -1 },
[cfg.down] = { 0, 1 },
[cfg.left] = { -1, 0 },
[cfg.right] = { 1, 0 },
[cfg.upLeft] = { -1, -1 },
[cfg.upRight] = { 1, -1 },
[cfg.downLeft] = { -1, 1 },
[cfg.downRight] = { 1, 1 },
}
for key in DIRS do
Bind(key, function() end)
end
local held = {}
for key, button in { [cfg.click] = "Mouse1", [cfg.rightClick] = "Mouse2", [cfg.middleClick] = "Mouse3" } do
Bind(key, {
action = function()
held[button] = true
HID.Down(button)
end,
release = function()
held[button] = nil
HID.Up(button)
end,
})
end
local dragging = false
Bind(cfg.drag, function()
dragging = not dragging
if dragging then
HID.Down("Mouse1")
else
HID.Up("Mouse1")
end
end)
function OnTick()
local dx, dy, longest = 0, 0, 0
for key, d in DIRS do
if Input.IsDown(key) then
dx, dy = dx + d[1], dy + d[2]
longest = math.max(longest, Input.GetDuration(key))
end
end
if dx == 0 and dy == 0 then
return
end
local t = if cfg.ramp > 0 then math.min(longest / cfg.ramp, 1) else 1
local speed = cfg.slow + (cfg.fast - cfg.slow) * t * t
HID.Move(math.round(dx * speed), math.round(dy * speed))
end
function OnStop()
if dragging then
HID.Up("Mouse1")
end
for button in held do
HID.Up(button)
end
end