aboutsummaryrefslogtreecommitdiffstats
path: root/mouse.lua
blob: 5a81708ae97d2e2aece1ffe762990e5725b298fe (plain)
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
mouse = {}
function mouse.bottom_left()
	local position = hs.mouse.getRelativePosition()
	position.x = position.x - 100
	position.y = position.y + 100
	hs.mouse.setRelativePosition(position)
end

function mouse.bottom()
	local position = hs.mouse.getRelativePosition()
	position.y = position.y + 100
	hs.mouse.setRelativePosition(position)
end

function mouse.bottom_right()
	local position = hs.mouse.getRelativePosition()
	position.x = position.x + 100
	position.y = position.y + 100
	hs.mouse.setRelativePosition(position)
end

function mouse.left()
	local position = hs.mouse.getRelativePosition()
	position.x = position.x - 100
	hs.mouse.setRelativePosition(position)
end

function mouse.click()
	local position = hs.mouse.getAbsolutePosition()
	hs.eventtap.leftClick(position)

	-- TODO: key down is mouse down, key up is mouse up
end

function mouse.right()
	local position = hs.mouse.getRelativePosition()
	position.x = position.x + 100
	hs.mouse.setRelativePosition(position)
end

function mouse.top_left()
	local position = hs.mouse.getRelativePosition()
	position.x = position.x - 100
	position.y = position.y - 100
	hs.mouse.setRelativePosition(position)
end

function mouse.top()
	local position = hs.mouse.getRelativePosition()
	position.y = position.y - 100
	hs.mouse.setRelativePosition(position)
end

function mouse.top_right()
	local position = hs.mouse.getRelativePosition()
	position.x = position.x + 100
	position.y = position.y - 100
	hs.mouse.setRelativePosition(position)
end


mouse_mode = hs.hotkey.modal.new({'ctrl', 'option', 'shift'}, 'm', 'Mouse')
mouse_mode:bind({'ctrl', 'option', 'shift'}, 'm', 'Mouse Off', function()
	mouse_mode:exit()
end)

mouse_mode:bind({}, 'pad1', mouse.bottom_left, nil, mouse.bottom_left)
mouse_mode:bind({}, 'pad2', mouse.bottom, nil, mouse.bottom)
mouse_mode:bind({}, 'pad3', mouse.bottom_right, nil, mouse.bottom_right)
mouse_mode:bind({}, 'pad4', mouse.left, nil, mouse.left)
mouse_mode:bind({}, 'pad5', mouse.click)
mouse_mode:bind({}, 'pad6', mouse.right, nil, mouse.right)
mouse_mode:bind({}, 'pad7', mouse.top_left, nil, mouse.top_left)
mouse_mode:bind({}, 'pad8', mouse.top, nil, mouse.top)
mouse_mode:bind({}, 'pad9', mouse.top_right, nil, mouse.top_right)