feat: Scroll Stash, closes #18

This commit is contained in:
Alexander Drozdov
2020-03-01 00:27:11 +02:00
parent 8384b0e9f1
commit ab2cfe10cc
2 changed files with 27 additions and 4 deletions
+1 -1
View File
@@ -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)
+26 -3
View File
@@ -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) {