Skip to content

Commit f232765

Browse files
committed
add keycode press
1 parent 6b21ad4 commit f232765

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "robotjs_addon",
3-
"version": "0.6.2",
3+
"version": "0.6.3",
44
"description": "Node.js Desktop Automation.",
55
"main": "index.js",
66
"typings": "index.d.ts",

src/keypress.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,26 @@ void typeKeycodeInWin(const char value)
322322
ip.ki.wScan = 0;
323323
ip.ki.time = 0;
324324
ip.ki.dwExtraInfo = 0;
325-
325+
SHORT vk = VkKeyScan(value);
326+
BYTE vkCode = vk & 0xff; // Extract the virtual-key code
327+
BYTE shiftState = vk >> 8; // Extract the shift state
328+
if (shiftState & 1) // Shift key
329+
{
330+
ip.ki.wVk = VK_SHIFT;
331+
ip.ki.dwFlags = 0; // 0 for key press
332+
SendInput(1, &ip, sizeof(INPUT));
333+
}
326334
// Press the key
327335
ip.ki.wVk = VkKeyScan(value);
328336
ip.ki.dwFlags = 0; // 0 for key press
329337
SendInput(1, &ip, sizeof(INPUT));
330338

339+
if (shiftState & 1) // Shift key
340+
{
341+
ip.ki.wVk = VK_SHIFT;
342+
ip.ki.dwFlags = KEYEVENTF_KEYUP;
343+
SendInput(1, &ip, sizeof(INPUT));
344+
}
331345
// Release the key
332346
ip.ki.dwFlags = KEYEVENTF_KEYUP;
333347
SendInput(1, &ip, sizeof(INPUT));

test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ var robot = require("./index");
22

33
//test mouse
44
// robot.dragMouse(200, 100);
5-
robot.moveMouse(365, 416);
6-
robot.mouseClick("left", true);
5+
// robot.moveMouse(365, 416);
6+
// robot.mouseClick("left", true);
77
// console.log(robot.getMousePos());
88

99
//test keyboard
1010
// robot.typeString("Hello World");
1111
// robot.keyTap("enter");
1212
// robot.keyTap("space", "control");
1313
// robot.typeString("你好");
14-
robot.typeKeyCodeStringInWin("124556asdjfkb");
14+
robot.typeKeyCodeStringInWin("124556abcdefg@COM");

0 commit comments

Comments
 (0)