From 1d4584b346ffb29ad0ef4b3d2472edadc282b700 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 13 Jun 2019 21:37:53 +0200 Subject: Add mouse hotkeys Proof of concept of shortcuts to move the mouse around. --- mouse.lua | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 mouse.lua (limited to 'mouse.lua') diff --git a/mouse.lua b/mouse.lua new file mode 100644 index 0000000..5a81708 --- /dev/null +++ b/mouse.lua @@ -0,0 +1,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) -- cgit v1.2.3