20 #include <freerdp/config.h>
22 #include <ApplicationServices/ApplicationServices.h>
23 #include <Carbon/Carbon.h>
25 #include <winpr/windows.h>
30 #include <freerdp/log.h>
31 #define TAG SERVER_TAG("mac")
33 static const CGKeyCode keymap[256] = {
61 kVK_ANSI_RightBracket,
89 kVK_ANSI_KeypadMultiply,
108 kVK_ANSI_KeypadMinus,
117 kVK_ANSI_KeypadDecimal,
291 BOOL mf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
293 CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
296 CGKeyCode kCode = 0xFF;
298 if (flags & KBD_FLAGS_RELEASE)
303 if (flags & KBD_FLAGS_EXTENDED)
309 kCode = kVK_ForwardDelete;
313 kCode = kVK_LeftArrow;
329 kCode = kVK_DownArrow;
337 kCode = kVK_PageDown;
341 kCode = kVK_RightArrow;
350 kCode = keymap[code];
353 kbEvent = CGEventCreateKeyboardEvent(source, kCode, keyDown);
354 CGEventPost(kCGHIDEventTap, kbEvent);
360 BOOL mf_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
365 BOOL mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
368 CGWheelCount wheelCount = 2;
372 if (flags & (PTR_FLAGS_WHEEL | PTR_FLAGS_HWHEEL))
374 INT32 scroll = flags & WheelRotationMask;
376 if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
377 scroll = -(flags & WheelRotationMask) / 392;
379 scroll = (flags & WheelRotationMask) / 120;
381 if (flags & PTR_FLAGS_WHEEL)
386 CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
387 CGEventRef scrollEvent = CGEventCreateScrollWheelEvent(source, kCGScrollEventUnitLine,
388 wheelCount, scroll_y, scroll_x);
389 CGEventPost(kCGHIDEventTap, scrollEvent);
390 CFRelease(scrollEvent);
396 CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
397 CGEventType mouseType = kCGEventNull;
398 CGMouseButton mouseButton = kCGMouseButtonLeft;
399 mfi = mf_info_get_instance();
401 width = (float)mfi->servscreen_width;
402 height = (
float)mfi->servscreen_height;
403 x += mfi->servscreen_xoffset;
404 y += mfi->servscreen_yoffset;
406 if (flags & PTR_FLAGS_MOVE)
408 if (mfi->mouse_down_left == TRUE)
410 mouseType = kCGEventLeftMouseDragged;
412 else if (mfi->mouse_down_right == TRUE)
414 mouseType = kCGEventRightMouseDragged;
416 else if (mfi->mouse_down_other == TRUE)
418 mouseType = kCGEventOtherMouseDragged;
422 mouseType = kCGEventMouseMoved;
425 CGEventRef move = CGEventCreateMouseEvent(source, mouseType, CGPointMake(x, y),
428 CGEventPost(kCGHIDEventTap, move);
432 if (flags & PTR_FLAGS_BUTTON1)
434 mouseButton = kCGMouseButtonLeft;
436 if (flags & PTR_FLAGS_DOWN)
438 mouseType = kCGEventLeftMouseDown;
439 mfi->mouse_down_left = TRUE;
443 mouseType = kCGEventLeftMouseUp;
444 mfi->mouse_down_right = FALSE;
447 else if (flags & PTR_FLAGS_BUTTON2)
449 mouseButton = kCGMouseButtonRight;
451 if (flags & PTR_FLAGS_DOWN)
453 mouseType = kCGEventRightMouseDown;
454 mfi->mouse_down_right = TRUE;
458 mouseType = kCGEventRightMouseUp;
459 mfi->mouse_down_right = FALSE;
462 else if (flags & PTR_FLAGS_BUTTON3)
464 mouseButton = kCGMouseButtonCenter;
466 if (flags & PTR_FLAGS_DOWN)
468 mouseType = kCGEventOtherMouseDown;
469 mfi->mouse_down_other = TRUE;
473 mouseType = kCGEventOtherMouseUp;
474 mfi->mouse_down_other = FALSE;
478 CGEventRef mouseEvent =
479 CGEventCreateMouseEvent(source, mouseType, CGPointMake(x, y), mouseButton);
480 CGEventPost(kCGHIDEventTap, mouseEvent);
481 CFRelease(mouseEvent);
488 BOOL mf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
493 BOOL mf_input_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code)
498 BOOL mf_input_unicode_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code)
503 BOOL mf_input_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
508 BOOL mf_input_extended_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)