diff --git a/src/main/positioning.ts b/src/main/positioning.ts index 71439adc..06f58efc 100644 --- a/src/main/positioning.ts +++ b/src/main/positioning.ts @@ -123,7 +123,7 @@ function getOffsetX (poePos: Rectangle): number { } } -function poeUserInterfaceWidth (windowHeight: number) { +export function poeUserInterfaceWidth (windowHeight: number) { // sidebar is 370px at 800x600 const ratio = 370 / 600 return Math.round(windowHeight * ratio) diff --git a/src/main/shortcuts.ts b/src/main/shortcuts.ts index 255fba40..929ac10f 100644 --- a/src/main/shortcuts.ts +++ b/src/main/shortcuts.ts @@ -4,11 +4,11 @@ import ioHook from 'iohook' import { pollClipboard } from './PollClipboard' import { win } from './window' import { windowManager } from './window-manager' -import { showWindow, lockWindow } from './positioning' +import { showWindow, lockWindow, poeUserInterfaceWidth } from './positioning' -const KEY_CTRL = 29 +// const KEY_CTRL = 29 +// const KEY_ALT = 56 const KEY_D = 32 -const KEY_ALT = 56 const KEY_F5 = 63 const POE_TITLE = 'Path of Exile' @@ -66,6 +66,29 @@ export function setupShortcuts () { robotjs.keyTap('key_c') }) + let naiveInventoryCheckX: number | undefined + ioHook.on('mousewheel', async (e: { ctrlKey?: true, x: number, rotation: 1 | -1 }) => { + if (!e.ctrlKey) return + if (naiveInventoryCheckX === undefined) { + if (await windowManager.getActiveWindowTitle() !== POE_TITLE) { + return + } else { + // NOTE: will not be updated if window moved + const poePos = await windowManager.getActiveWindowContentBounds() + naiveInventoryCheckX = (poePos!.x + poePos!.width) - poeUserInterfaceWidth(poePos!.height) + } + } + + const mouseX = (process.platform === 'linux') ? screen.getCursorScreenPoint().x : e.x + if (mouseX > naiveInventoryCheckX) { + if (e.rotation > 0) { + robotjs.keyTap('right') + } else if (e.rotation < 0) { + robotjs.keyTap('left') + } + } + }) + ioHook.registerShortcut([KEY_F5], () => { /* ignore keydown */ }, async () => { const title = await windowManager.getActiveWindowTitle() if (title === POE_TITLE) {