Skip to content
This repository was archived by the owner on Jun 19, 2021. It is now read-only.

Commit 8bd4c5c

Browse files
author
Simon Hofmann
committed
0.5.1
1 parent 38ed4c3 commit 8bd4c5c

File tree

4 files changed

+30
-40
lines changed

4 files changed

+30
-40
lines changed

src/keypress.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ void toggleUnicodeKey(unsigned long ch, const bool down)
206206

207207
if (ch > 0xFFFF) {
208208
// encode to utf-16 if necessary
209-
UniChar surrogates[2] = {
209+
unsigned short surrogates[] = {
210210
0xD800 + ((ch - 0x10000) >> 10),
211211
0xDC00 + (ch & 0x3FF)
212212
};
213213

214-
CGEventKeyboardSetUnicodeString(keyEvent, 2, (UniChar*) &surrogates);
214+
CGEventKeyboardSetUnicodeString(keyEvent, 2, &surrogates);
215215
} else {
216-
CGEventKeyboardSetUnicodeString(keyEvent, 1, (UniChar*) &ch);
216+
CGEventKeyboardSetUnicodeString(keyEvent, 1, &ch);
217217
}
218218

219219
CGEventPost(kCGSessionEventTap, keyEvent);

src/mouse.c

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ void moveMouse(MMPoint point)
118118
mouseInput.mi.dwExtraInfo = 0;
119119
mouseInput.mi.mouseData = 0;
120120
SendInput(1, &mouseInput, sizeof(mouseInput));
121+
121122
#endif
122123
}
123124

@@ -185,15 +186,7 @@ void toggleMouse(bool down, MMMouseButton button)
185186
XTestFakeButtonEvent(display, button, down ? True : False, CurrentTime);
186187
XSync(display, false);
187188
#elif defined(IS_WINDOWS)
188-
INPUT mouseInput;
189-
mouseInput.type = INPUT_MOUSE;
190-
mouseInput.mi.dx = 0;
191-
mouseInput.mi.dy = 0;
192-
mouseInput.mi.dwFlags = MMMouseToMEventF(down, button);
193-
mouseInput.mi.time = 0; //System will provide the timestamp
194-
mouseInput.mi.dwExtraInfo = 0;
195-
mouseInput.mi.mouseData = 0;
196-
SendInput(1, &mouseInput, sizeof(mouseInput));
189+
mouse_event(MMMouseToMEventF(down, button), 0, 0, 0, 0);
197190
#endif
198191
}
199192

@@ -244,7 +237,8 @@ void scrollMouse(int x, int y)
244237
#if defined(IS_WINDOWS)
245238
// Fix for #97 https://github.com/octalmage/robotjs/issues/97,
246239
// C89 needs variables declared on top of functions (mouseScrollInput)
247-
INPUT mouseScrollInputs[2];
240+
INPUT mouseScrollInputH;
241+
INPUT mouseScrollInputV;
248242
#endif
249243

250244
/* Direction should only be considered based on the scrollDirection. This
@@ -300,24 +294,25 @@ void scrollMouse(int x, int y)
300294

301295
#elif defined(IS_WINDOWS)
302296

303-
mouseScrollInputs[0].type = INPUT_MOUSE;
304-
mouseScrollInputs[0].mi.dx = 0;
305-
mouseScrollInputs[0].mi.dy = 0;
306-
mouseScrollInputs[0].mi.dwFlags = MOUSEEVENTF_HWHEEL;
307-
mouseScrollInputs[0].mi.time = 0;
308-
mouseScrollInputs[0].mi.dwExtraInfo = 0;
297+
mouseScrollInputH.type = INPUT_MOUSE;
298+
mouseScrollInputH.mi.dx = 0;
299+
mouseScrollInputH.mi.dy = 0;
300+
mouseScrollInputH.mi.dwFlags = MOUSEEVENTF_HWHEEL;
301+
mouseScrollInputH.mi.time = 0;
302+
mouseScrollInputH.mi.dwExtraInfo = 0;
309303
// Flip x to match other platforms.
310-
mouseScrollInputs[0].mi.mouseData = -x;
311-
312-
mouseScrollInputs[1].type = INPUT_MOUSE;
313-
mouseScrollInputs[1].mi.dx = 0;
314-
mouseScrollInputs[1].mi.dy = 0;
315-
mouseScrollInputs[1].mi.dwFlags = MOUSEEVENTF_WHEEL;
316-
mouseScrollInputs[1].mi.time = 0;
317-
mouseScrollInputs[1].mi.dwExtraInfo = 0;
318-
mouseScrollInputs[1].mi.mouseData = y;
319-
320-
SendInput(2, mouseScrollInputs, sizeof(mouseScrollInputs));
304+
mouseScrollInputH.mi.mouseData = -x;
305+
306+
mouseScrollInputV.type = INPUT_MOUSE;
307+
mouseScrollInputV.mi.dx = 0;
308+
mouseScrollInputV.mi.dy = 0;
309+
mouseScrollInputV.mi.dwFlags = MOUSEEVENTF_WHEEL;
310+
mouseScrollInputV.mi.time = 0;
311+
mouseScrollInputV.mi.dwExtraInfo = 0;
312+
mouseScrollInputV.mi.mouseData = y;
313+
314+
SendInput(1, &mouseScrollInputH, sizeof(mouseScrollInputH));
315+
SendInput(1, &mouseScrollInputV, sizeof(mouseScrollInputV));
321316
#endif
322317
}
323318

src/robotjs.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,23 +415,23 @@ int CheckKeyFlags(char* f, MMKeyFlags* flags)
415415
return 0;
416416
}
417417

418-
int GetFlagsFromString(v8::Local<v8::Value> value, MMKeyFlags* flags)
418+
int GetFlagsFromString(v8::Handle<v8::Value> value, MMKeyFlags* flags)
419419
{
420420
v8::String::Utf8Value fstr(value->ToString());
421421
return CheckKeyFlags(*fstr, flags);
422422
}
423423

424-
int GetFlagsFromValue(v8::Local<v8::Value> value, MMKeyFlags* flags)
424+
int GetFlagsFromValue(v8::Handle<v8::Value> value, MMKeyFlags* flags)
425425
{
426426
if (!flags) return -1;
427427

428428
//Optionally allow an array of flag strings to be passed.
429429
if (value->IsArray())
430430
{
431-
v8::Local<v8::Array> a = v8::Local<v8::Array>::Cast(value);
431+
v8::Handle<v8::Array> a = v8::Handle<v8::Array>::Cast(value);
432432
for (uint32_t i = 0; i < a->Length(); i++)
433433
{
434-
v8::Local<v8::Value> v(a->Get(i));
434+
v8::Handle<v8::Value> v(a->Get(i));
435435
if (!v->IsString()) return -2;
436436

437437
MMKeyFlags f = MOD_NONE;

test/integration/mouse.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ robot.setMouseDelay(100);
88
var target, elements;
99

1010
describe('Integration/Mouse', () => {
11-
let defaultTimeout;
1211
beforeEach(done => {
13-
defaultTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
14-
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
15-
1612
target = targetpractice.start();
1713
target.once('elements', message => {
1814
elements = message;
@@ -21,7 +17,6 @@ describe('Integration/Mouse', () => {
2117
});
2218

2319
afterEach(() => {
24-
jasmine.DEFAULT_TIMEOUT_INTERVAL = defaultTimeout;
2520
targetpractice.stop();
2621
target = null;
2722
});
@@ -40,7 +35,7 @@ describe('Integration/Mouse', () => {
4035
// Click it!
4136
robot.moveMouse(button_1.x, button_1.y);
4237
robot.mouseClick();
43-
})
38+
});
4439

4540
it('scrolls vertically', done => {
4641
target.once('scroll', element => {

0 commit comments

Comments
 (0)