Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions packages/mac-input/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# @intuiter/mac-input

macOS keyboard/mouse control for Intuiter using [Hammerspoon](https://www.hammerspoon.org/).

## Features

### Mouse Control (Cmd + IJKL)
- **Cmd + I/K/J/L**: Move mouse up/down/left/right
- **Diagonal**: Hold two keys (e.g., Cmd + I + L for up-right)
- **Speed**: Hold Ctrl for instant max speed

### Mouse Clicks
- **Cmd + U**: Left click (hold for drag)
- **Cmd + O**: Right click
- **Cmd + M**: Middle click

### Scrolling
- **Alt + U/O**: Scroll up/down
- **Alt + Shift + U/O**: Scroll left/right
- **Cmd + H/P**: Scroll up/down (alternate)

### Text Navigation (Alt + IJKL)
- **Alt + I/K**: Arrow up/down
- **Alt + J/L**: Word left/right
- **Alt + Shift + variants**: Select while moving
- **Alt + Ctrl + variants**: Repeat while held

### Text Selection
- **Alt + W**: Select word (press twice for line)
- **Alt + A**: Select line (press twice for paragraph)
- **Alt + Shift + W**: Select entire line

## Installation

### Via npm
```bash
cd packages/mac-input
npm run install-config
```

### Manual
1. Install Hammerspoon: `brew install --cask hammerspoon`
2. Copy files from `hammerspoon/` to `~/.hammerspoon/`
3. Grant Accessibility permissions in System Preferences
4. Reload config: Cmd + Ctrl + R

## Configuration

Edit `~/.hammerspoon/config.lua`:

```lua
config.mouse = {
maxVelocity = 5,
acceleration = 0.2,
pollInterval = 0.001,
}
```

## Windows/Mac Comparison

| Feature | Windows (AHK) | macOS (Hammerspoon) |
|---------|---------------|---------------------|
| Mouse movement | LWin + IJKL | Cmd + IJKL |
| Clicks | LWin + U/O | Cmd + U/O |
| Text nav | LAlt + IJKL | Alt + IJKL |

## License

MIT
29 changes: 5 additions & 24 deletions packages/mac-input/hammerspoon/mouse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ local function stopMouseMove()
end

-- Generic mouse movement function
local function startMouseMove(dirX, dirY)
local function startMouseMove()
stopMouseMove()
state.velocity = 0

Expand Down Expand Up @@ -105,19 +105,7 @@ local function startMouseMove(dirX, dirY)
end)
end

-- Mouse click functions (equivalent to click_left, click_right, click_mid in AHK)
local function mouseClick(button)
local pos = hs.mouse.absolutePosition()
hs.eventtap.event.newMouseEvent(
hs.eventtap.event.types[button .. "MouseDown"],
pos
):post()
hs.eventtap.event.newMouseEvent(
hs.eventtap.event.types[button .. "MouseUp"],
pos
):post()
end

-- Mouse click functions
local function mouseDown(button)
local pos = hs.mouse.absolutePosition()
hs.eventtap.event.newMouseEvent(
Expand All @@ -134,7 +122,7 @@ local function mouseUp(button)
):post()
end

-- Scroll functions (equivalent to scroll_up, scroll_down, etc. in AHK)
-- Scroll functions
local scrollState = {
timer = nil,
divisor = 3,
Expand Down Expand Up @@ -168,12 +156,10 @@ local function startScroll(dx, dy)
end

-- Key bindings for mouse movement (Cmd + IJKL)
-- Equivalent to Lwin & i, Lwin & k, Lwin & j, Lwin & l in AHK
local moveKeys = {"i", "j", "k", "l"}
local moveBindings = {}

for _, key in ipairs(moveKeys) do
-- Key down
moveBindings[key .. "_down"] = hs.hotkey.bind({"cmd"}, key, function()
setKeyPressed(key, true)
startMouseMove()
Expand All @@ -182,8 +168,7 @@ for _, key in ipairs(moveKeys) do
end)
end

-- Mouse click bindings (Cmd + U for left click, Cmd + O for right click)
-- Equivalent to Lwin & u, Lwin & o in AHK
-- Mouse click bindings
local leftClickBinding = hs.hotkey.bind({"cmd"}, "u", function()
mouseDown("left")
end, function()
Expand All @@ -196,15 +181,13 @@ end, function()
mouseUp("right")
end)

-- Middle click (Cmd + M)
local midClickBinding = hs.hotkey.bind({"cmd"}, "m", function()
mouseDown("middle")
end, function()
mouseUp("middle")
end)

-- Scroll bindings (Alt + U for scroll up, Alt + O for scroll down)
-- Equivalent to Lalt & u, Lalt & o in AHK
-- Scroll bindings
local scrollUpBinding = hs.hotkey.bind({"alt"}, "u", function()
startScroll(0, 5)
end, function()
Expand All @@ -217,7 +200,6 @@ end, function()
stopScroll()
end)

-- Horizontal scroll with Shift modifier
local scrollLeftBinding = hs.hotkey.bind({"alt", "shift"}, "u", function()
startScroll(5, 0)
end, function()
Expand All @@ -230,7 +212,6 @@ end, function()
stopScroll()
end)

-- Additional scroll binding (Cmd + H for scroll up, Cmd + P for scroll down)
local scrollUpAltBinding = hs.hotkey.bind({"cmd"}, "h", function()
startScroll(0, 5)
end, function()
Expand Down
Loading