Skip to content

Commit

Permalink
defeated input delays. HO shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
SnosMe committed Jan 9, 2020
1 parent 4fe7467 commit 8a194e4
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 17 deletions.
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
"electron:publish": "vue-cli-service electron:build -p onTagOrDraft",
"electron:serve": "vue-cli-service electron:serve",
"electron:generate-icons": "electron-icon-builder --input=./public/icon.png --output=build --flatten",
"postinstall": "electron-builder install-app-deps",
"postinstall": "patch-package && electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
},
"author": { "name": "Alexander Drozdov" },
"repository": { "type": "git", "url": "https://github.com/SnosMe/awakened-poe-trade.git" },
"author": {
"name": "Alexander Drozdov"
},
"repository": {
"type": "git",
"url": "https://github.com/SnosMe/awakened-poe-trade.git"
},
"main": "background.js",
"dependencies": {
"core-js": "^2.6.5",
Expand All @@ -41,7 +46,9 @@
"electron-icon-builder": "^1.0.2",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"patch-package": "^6.2.0",
"postcss-nested": "^4.2.1",
"postinstall-postinstall": "^2.0.0",
"typescript": "^3.4.3",
"vue-cli-plugin-electron-builder": "^1.4.4",
"vue-template-compiler": "^2.6.10"
Expand Down
23 changes: 23 additions & 0 deletions patches/robotjs+0.6.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/node_modules/robotjs/src/keypress.c b/node_modules/robotjs/src/keypress.c
index 2bbdccd..ec19c80 100644
--- a/node_modules/robotjs/src/keypress.c
+++ b/node_modules/robotjs/src/keypress.c
@@ -16,7 +16,7 @@
/* Convenience wrappers around ugly APIs. */
#if defined(IS_WINDOWS)
#define WIN32_KEY_EVENT_WAIT(key, flags) \
- (win32KeyEvent(key, flags), Sleep(DEADBEEF_RANDRANGE(63, 125)))
+ (win32KeyEvent(key, flags))
#elif defined(USE_X11)
#define X_KEY_EVENT(display, key, is_press) \
(XTestFakeKeyEvent(display, \
@@ -24,8 +24,7 @@
is_press, CurrentTime), \
XSync(display, false))
#define X_KEY_EVENT_WAIT(display, key, is_press) \
- (X_KEY_EVENT(display, key, is_press), \
- microsleep(DEADBEEF_UNIFORM(62.5, 125.0)))
+ (X_KEY_EVENT(display, key, is_press))
#endif

#if defined(IS_MACOSX)
32 changes: 23 additions & 9 deletions src/components/electron-main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { BrowserWindow, screen, Rectangle, ipcMain, Point } from 'electron'
import { keyTap } from 'robotjs'
import { windowManager } from 'node-window-manager'
import robotjs from 'robotjs'
import ioHook from 'iohook'
import { pollClipboard } from './PollClipboard'

const KEY_CTRL = 29
const KEY_D = 32
const KEY_F5 = 63
const POE_TITLE = 'Path of Exile'

const CLOSE_THRESHOLD_PX = 40

Expand All @@ -14,6 +16,11 @@ let checkPressPosition: Point | undefined
let isCtrlDown = false

export function setupShortcuts (win: BrowserWindow) {
// A value of zero causes the thread to relinquish the remainder of its
// time slice to any other thread that is ready to run. If there are no other
// threads ready to run, the function returns immediately
robotjs.setKeyboardDelay(0)

ioHook.registerShortcut([KEY_CTRL, KEY_D], () => {
if (!isPollingClipboard) {
isPollingClipboard = true
Expand All @@ -30,13 +37,7 @@ export function setupShortcuts (win: BrowserWindow) {
// keyTap('c', ['control']) must be never used
// - this callback called on "keypress" not "keyup"
// - ability to price multiple items with holded Ctrl, while variant above will change Ctrl key state to "up"
// Known bugs:
// - press Ctrl+D very very often, or just hold down Ctrl+D
// After releasing keys "Character Screen" will flesh ~times~
// Because Ctrl is released, but event loop still has events
// Alternative impl:
// - use Ctrl+C, as original XenoTrade does
keyTap('c')
robotjs.keyTap('c')
}, () => {
// both keys released
})
Expand All @@ -51,6 +52,20 @@ export function setupShortcuts (win: BrowserWindow) {
}
})

ioHook.registerShortcut([KEY_F5], () => { /* ignore keydown */ }, () => {
const window = windowManager.getActiveWindow()
if (window && window.getTitle() === POE_TITLE) {
robotjs.keyTap('enter')
robotjs.typeString('/hideout')
robotjs.keyTap('enter')
// restore the last chat
robotjs.keyTap('enter')
robotjs.keyTap('up')
robotjs.keyTap('up')
robotjs.keyTap('escape')
}
})

const DEBUG_IO_HOOK = false
ioHook.start(DEBUG_IO_HOOK)
}
Expand All @@ -60,7 +75,6 @@ export function setupShowHide (win: BrowserWindow) {
if (isVisible) {
positionWindow(win)
win.showInactive()
// setup listener mouse move
} else {
checkPressPosition = undefined
win.hide()
Expand Down
Loading

0 comments on commit 8a194e4

Please sign in to comment.