Пример #1
0
void convertAndSendVK(PRUint8 vk, bool down) {
    CGKeyCode key = 0;

    // Hack
    usleep(100);

    switch (vk) {
        case SPACE:
            key = kVK_Space;
            break;
        case BKSP:
            key = kVK_Delete;
            break;
        case TAB:
            key = kVK_Tab;
            break;
        case ENTER:
            key = kVK_Return;
            break;
        case SHIFT:
            key = kVK_Shift;
            break;
        default:
            return;
    }

    CGEventRef event;
    CGEventSourceRef eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
    event = CGEventCreateKeyboardEvent (eventSource, key, down);
    CGEventPost(kCGHIDEventTap, event);
    CFRelease(eventSource);
    CFRelease(event);
}
Пример #2
0
int inputopen(int index){
    CGEventSourceRef event = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
    if(!event){
        keyboard[index].event = 0;
        return 0;
    }
    keyboard[index].event = event;
    return 1;
}
Пример #3
0
void Utilities::PostKey(CGKeyCode key)
{
    CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
    
    CGEventRef keyDown = CGEventCreateKeyboardEvent(source, key, TRUE);
    CGEventRef keyUp = CGEventCreateKeyboardEvent(source, key, FALSE);
    
    CGEventPost(kCGAnnotatedSessionEventTap, keyDown);
    CGEventPost(kCGAnnotatedSessionEventTap, keyUp);
    
    CFRelease(keyUp);
    CFRelease(keyDown);
    CFRelease(source);
}
Пример #4
0
/* void char_down (in char key); */
NS_IMETHODIMP SendKeys::Char_down(PRUnichar key) {
#if _DEBUG
    printf("charDown: %c (%d)\n", key, key);
#endif
    UniChar letter = key;
    CGEventRef event;
    CGEventSourceRef eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
    event = CGEventCreateKeyboardEvent (eventSource, 1, true);
    CGEventKeyboardSetUnicodeString(event, 1, &letter);
    CGEventPost(kCGHIDEventTap, event);
    CFRelease(event);
    CFRelease(eventSource);

    return NS_OK;
}
Пример #5
0
void mouseControl::leftMouseDragged(ofPoint myMouse){
    mouseCursorPosition.x = myMouse.x;
    mouseCursorPosition.y = myMouse.y;
     #ifdef TARGET_OSX
    CGMouseButton mouseButton = kCGMouseButtonLeft;

    mouseEventLeftDragged = CGEventCreateMouseEvent (  CGEventSourceCreate(NULL),
                                                     eventTypeLeftDragged,
                                                     mouseCursorPosition,
                                                     kCGMouseButtonLeft );
    CGEventSetType(mouseEventLeftDragged, kCGEventLeftMouseDragged); // Fix Apple Bug
    CGEventPost( kCGSessionEventTap, mouseEventLeftDragged );
     #endif
    draggingLeftButton = true;
}
Пример #6
0
void mouseControl::rightButtonDown(ofPoint myMouse){
    mouseCursorPosition.x = myMouse.x;
    mouseCursorPosition.y = myMouse.y;
     #ifdef TARGET_OSX
    CGMouseButton mouseButton = kCGMouseButtonRight;

    mouseEventRightDown = CGEventCreateMouseEvent (  CGEventSourceCreate(NULL),
                                                 eventTypeRightMouseDown,
                                                 mouseCursorPosition,
                                                 kCGMouseButtonRight );
    CGEventSetType(mouseEventRightDown, kCGEventRightMouseDown); // Fix Apple Bug
    CGEventPost( kCGSessionEventTap, mouseEventRightDown );
    CFRelease(mouseEventRightDown);
    #endif
    mRightButton = true;
}
Пример #7
0
void mouseControl::move(ofPoint myMouse){
    mouseCursorPosition.x = myMouse.x;
    mouseCursorPosition.y = myMouse.y;

     #ifdef TARGET_OSX
    mouseEventMove = CGEventCreateMouseEvent ( CGEventSourceCreate(NULL),
                                                         eventTypeMouseMoved,
                                                         mouseCursorPosition,
                                                         kCGMouseButtonLeft);//ignored
                                                //kCGMouseButtonRight);
                                                  //kCGMouseButtonLeft);
    CGEventSetType(mouseEventMove, kCGEventMouseMoved); // Fix Apple Bug
    CGEventPost( kCGSessionEventTap, mouseEventMove );

    //if(ofGetElapsedTimef() > 1000)
       CFRelease(mouseEventMove);
       #endif
}
Пример #8
0
void mac_shadow_input_keyboard_event(macShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code)
{
	DWORD vkcode;
	DWORD keycode;
	BOOL extended;
	CGEventRef kbdEvent;
	CGEventSourceRef source;
	
	extended = (flags & KBD_FLAGS_EXTENDED) ? TRUE : FALSE;
	
	if (extended)
		code |= KBDEXT;
	
	vkcode = GetVirtualKeyCodeFromVirtualScanCode(code, 4);
	
	if (extended)
		vkcode |= KBDEXT;
	
	keycode = GetKeycodeFromVirtualKeyCode(vkcode, KEYCODE_TYPE_APPLE);
	
	if (keycode < 8)
		return;
	
	keycode -= 8;

	source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
	
	if (flags & KBD_FLAGS_DOWN)
	{
		kbdEvent = CGEventCreateKeyboardEvent(source, (CGKeyCode) keycode, TRUE);
		CGEventPost(kCGHIDEventTap, kbdEvent);
		CFRelease(kbdEvent);
	}
	else if (flags & KBD_FLAGS_RELEASE)
	{
		kbdEvent = CGEventCreateKeyboardEvent(source, (CGKeyCode) keycode, FALSE);
		CGEventPost(kCGHIDEventTap, kbdEvent);
		CFRelease(kbdEvent);
	}
	
	CFRelease(source);
}
Пример #9
0
void mouseControl::rightButtonUp(ofPoint myMouse){
    mouseCursorPosition.x = myMouse.x;
    mouseCursorPosition.y = myMouse.y;
     #ifdef TARGET_OSX
    CGMouseButton mouseButton = kCGMouseButtonRight;

    mouseEventRightUp = CGEventCreateMouseEvent (  CGEventSourceCreate(NULL),
                                                      eventTypeRightMouseUp,
                                                      mouseCursorPosition,
                                                      kCGMouseButtonRight );
    CGEventSetType(mouseEventRightUp, kCGEventRightMouseUp); // Fix Apple Bug
    CGEventPost( kCGSessionEventTap, mouseEventRightUp );
    CFRelease(mouseEventRightUp);
    mRightButton = false;
    if(draggingRightButton){
        CFRelease(mouseEventRightDragged);
        draggingRightButton = false;
    }
    #endif
}
Пример #10
0
void mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{
	float width, height;
	
	CGWheelCount wheelCount = 2;
	UINT32 scroll_x = 0;
	UINT32 scroll_y = 0;
	
	if (flags & PTR_FLAGS_WHEEL)
	{
		scroll_y = flags & WheelRotationMask;
		
		if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
		{
			scroll_y = -(flags & WheelRotationMask) / 392;
		}
		else
		{
			scroll_y = (flags & WheelRotationMask) / 120;
		}
		
		CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState);
		CGEventRef scroll = CGEventCreateScrollWheelEvent(source,
								  kCGScrollEventUnitLine,
								  wheelCount,
								  scroll_y,
								  scroll_x);
		CGEventPost(kCGHIDEventTap, scroll);
		
		CFRelease(scroll);
		CFRelease(source);
	}
	/*
	 ///////////////////////////////////////////////
	 // We dont support horizontal scrolling yet...
	 ///////////////////////////////////////////////
	else if (flags & PTR_FLAGS_)
	{
		scroll_y = flags & WheelRotationMask;
		
		if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
		{
			scroll_y = -(flags & WheelRotationMask) / 392;
		}
		else
		{
			scroll_y = (flags & WheelRotationMask) / 120;
		}
		
		CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateCombinedSessionState);
		CGEventRef scroll = CGEventCreateScrollWheelEvent(source,
								  kCGScrollEventUnitLine,
								  wheelCount,
								  scroll_y,
								  scroll_x);
		CGEventPost(kCGHIDEventTap, scroll);
		
		CFRelease(scroll);
		CFRelease(source);
	} */
	else
	{
		
		mfInfo * mfi;
		CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState);
		CGEventType mouseType = kCGEventNull;
		CGMouseButton mouseButton = kCGMouseButtonLeft;
		
		
		mfi = mf_info_get_instance();
		
		//width and height of primary screen (even in multimon setups
		width = (float) mfi->servscreen_width;
		height = (float) mfi->servscreen_height;
		
		x += mfi->servscreen_xoffset;
		y += mfi->servscreen_yoffset;
		
		if (flags & PTR_FLAGS_MOVE)
		{
			if (mfi->mouse_down_left == TRUE)
			{
				mouseType = kCGEventLeftMouseDragged;
			}
			else if (mfi->mouse_down_right == TRUE)
			{
				mouseType = kCGEventRightMouseDragged;
			}
			else if (mfi->mouse_down_other == TRUE)
			{
				mouseType = kCGEventOtherMouseDragged;
			}
			else
			{
				mouseType = kCGEventMouseMoved;
			}
			
			CGEventRef move = CGEventCreateMouseEvent(source,
								  mouseType,
								  CGPointMake(x, y),
								  mouseButton // ignored for just movement
								  );
			
			CGEventPost(kCGHIDEventTap, move);
			
			CFRelease(move);
		}
		
		if (flags & PTR_FLAGS_BUTTON1)
		{
			mouseButton = kCGMouseButtonLeft;
			if (flags & PTR_FLAGS_DOWN)
			{
				mouseType = kCGEventLeftMouseDown;
				mfi->mouse_down_left = TRUE;
			}
			else
			{
				mouseType = kCGEventLeftMouseUp;
				mfi->mouse_down_right = FALSE;
			}
		}
		else if (flags & PTR_FLAGS_BUTTON2)
		{
			mouseButton = kCGMouseButtonRight;
			if (flags & PTR_FLAGS_DOWN)
			{
				mouseType = kCGEventRightMouseDown;
				mfi->mouse_down_right = TRUE;
			}
			else
			{
				mouseType = kCGEventRightMouseUp;
				mfi->mouse_down_right = FALSE;
			}
			
		}
		else if (flags & PTR_FLAGS_BUTTON3)
		{
			mouseButton = kCGMouseButtonCenter;
			if (flags & PTR_FLAGS_DOWN)
			{
				mouseType = kCGEventOtherMouseDown;
				mfi->mouse_down_other = TRUE;
			}
			else
			{
				mouseType = kCGEventOtherMouseUp;
				mfi->mouse_down_other = FALSE;
			}
			
		}
		
		
		CGEventRef mouseEvent = CGEventCreateMouseEvent(source,
								mouseType,
								CGPointMake(x, y),
								mouseButton
								);
		CGEventPost(kCGHIDEventTap, mouseEvent);
		
		CFRelease(mouseEvent);
		CFRelease(source);
	}
}
Пример #11
0
void mf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{
	CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState);
	
	BOOL keyDown = TRUE;
	CGEventRef kbEvent;
	CGKeyCode kCode = 0xFF;
	
	if (flags & KBD_FLAGS_RELEASE)
	{
		keyDown = FALSE;
	}
	
	if (flags & KBD_FLAGS_EXTENDED)
	{
		switch (code) {
			//case 0x52: //insert
			case 0x53:
				kCode = kVK_ForwardDelete;
				break;
				
			case 0x4B:
				kCode = kVK_LeftArrow;
				break;
				
			case 0x47:
				kCode = kVK_Home;
				break;
				
			case 0x4F:
				kCode = kVK_End;
				break;
				
			case 0x48:
				kCode = kVK_UpArrow;
				break;
				
			case 0x50:
				kCode = kVK_DownArrow;
				break;
				
			case 0x49:
				kCode = kVK_PageUp;
				break;
				
			case 0x51:
				kCode = kVK_PageDown;
				break;
				
			case 0x4D:
				kCode = kVK_RightArrow;
				break;
				
			default:
				break;
		}
	}
	else
	{
		kCode = keymap[code];
	}
	
	kbEvent = CGEventCreateKeyboardEvent(source, kCode, keyDown);
	CGEventPost(kCGHIDEventTap, kbEvent);
	CFRelease(kbEvent);
	CFRelease(source);
	
	/*
	if (flags & KBD_FLAGS_EXTENDED)
		printf("extended ");
	printf("keypress: down = %d, SCAN=%#0X, VK=%#0X\n", keyDown, code, keymap[code]);
	*/
}
Пример #12
0
static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem,
        rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y)
{
	UINT32 scrollX = 0;
	UINT32 scrollY = 0;
	CGWheelCount wheelCount = 2;

	if (flags & PTR_FLAGS_WHEEL)
	{
		scrollY = flags & WheelRotationMask;

		if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
		{
			scrollY = -(flags & WheelRotationMask) / 392;
		}
		else
		{
			scrollY = (flags & WheelRotationMask) / 120;
		}

		CGEventSourceRef source = CGEventSourceCreate(
		                              kCGEventSourceStateHIDSystemState);
		CGEventRef scroll = CGEventCreateScrollWheelEvent(source,
		                    kCGScrollEventUnitLine,
		                    wheelCount, scrollY, scrollX);
		CGEventPost(kCGHIDEventTap, scroll);
		CFRelease(scroll);
		CFRelease(source);
	}
	else
	{
		CGEventSourceRef source = CGEventSourceCreate(
		                              kCGEventSourceStateHIDSystemState);
		CGEventType mouseType = kCGEventNull;
		CGMouseButton mouseButton = kCGMouseButtonLeft;

		if (flags & PTR_FLAGS_MOVE)
		{
			if (subsystem->mouseDownLeft)
				mouseType = kCGEventLeftMouseDragged;
			else if (subsystem->mouseDownRight)
				mouseType = kCGEventRightMouseDragged;
			else if (subsystem->mouseDownOther)
				mouseType = kCGEventOtherMouseDragged;
			else
				mouseType = kCGEventMouseMoved;

			CGEventRef move = CGEventCreateMouseEvent(source, mouseType, CGPointMake(x, y),
			                  mouseButton);
			CGEventPost(kCGHIDEventTap, move);
			CFRelease(move);
		}

		if (flags & PTR_FLAGS_BUTTON1)
		{
			mouseButton = kCGMouseButtonLeft;

			if (flags & PTR_FLAGS_DOWN)
			{
				mouseType = kCGEventLeftMouseDown;
				subsystem->mouseDownLeft = TRUE;
			}
			else
			{
				mouseType = kCGEventLeftMouseUp;
				subsystem->mouseDownLeft = FALSE;
			}
		}
		else if (flags & PTR_FLAGS_BUTTON2)
		{
			mouseButton = kCGMouseButtonRight;

			if (flags & PTR_FLAGS_DOWN)
			{
				mouseType = kCGEventRightMouseDown;
				subsystem->mouseDownRight = TRUE;
			}
			else
			{
				mouseType = kCGEventRightMouseUp;
				subsystem->mouseDownRight = FALSE;
			}
		}
		else if (flags & PTR_FLAGS_BUTTON3)
		{
			mouseButton = kCGMouseButtonCenter;

			if (flags & PTR_FLAGS_DOWN)
			{
				mouseType = kCGEventOtherMouseDown;
				subsystem->mouseDownOther = TRUE;
			}
			else
			{
				mouseType = kCGEventOtherMouseUp;
				subsystem->mouseDownOther = FALSE;
			}
		}

		CGEventRef mouseEvent = CGEventCreateMouseEvent(source, mouseType,
		                        CGPointMake(x, y), mouseButton);
		CGEventPost(kCGHIDEventTap, mouseEvent);
		CFRelease(mouseEvent);
		CFRelease(source);
	}
}
Пример #13
0
// Return true if the event is handled, return false otherwise and if the event should not be interrupted
bool MouseEventTool::HandleMouseEvent(CGEventType type, CGEventRef event) {
    // Check our full screen state so we can hackily reset it if it gets messed up
    if (shouldMakeFullScreenOrNot_) {
        if (IsMenuBarVisible()) {
            ::SetSystemUIMode(kUIModeAllHidden, 0);
        }
    }

    if (type == kCGEventKeyUp || type == kCGEventKeyDown) {
        // Don't do anything to key events
        return false;
    }

    CGPoint mouseLocation = CGEventGetLocation(event);
    double scrollMotion = CGEventGetDoubleValueField(event, kCGScrollWheelEventDeltaAxis1);

    if (mouseEventCallback_ != NULL) {
        int dx = 0;
        int dy = 0;
        if (prevX_ >= 0) {
            dx = mouseLocation.x - prevX_;
            dy = mouseLocation.y - prevY_;
        }

        mouseEventCallback_->MouseEvent(macEventToWindowsEventType(type), mouseLocation.x, mouseLocation.y, dx, dy, scrollMotion);
    }

    prevX_ = mouseLocation.x;
    prevY_ = mouseLocation.y;

    int eventTypeEnum = macEventToEnum(type);
    if (eventTypeEnum == -1) {
        return false;
    }

    isFullScreen_ = isFullScreenWindow();
    short resultKey = buttonMapping_[eventTypeEnum];

    if (resultKey != -1) {
        if (resultKey != VK_NO_EVENT) {
            CGEventRef eventDown, eventUp;
            CGEventRef commandDown, commandUp;
            CGEventSourceRef eventSource = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
            CGKeyCode keyToSend = resultKey;

            if (resultKey == VK_BROWSER_BACK && isFullScreen_) {
                keyToSend = kVK_Escape;
            } else if (resultKey == VK_BROWSER_BACK) {
                commandDown = CGEventCreateKeyboardEvent(eventSource, kVK_Command, true);
                keyToSend = kVK_ANSI_LeftBracket;

                CGEventPost(kCGHIDEventTap, commandDown);
            }

            eventDown = CGEventCreateKeyboardEvent (eventSource, keyToSend, true);
            eventUp = CGEventCreateKeyboardEvent (eventSource, keyToSend, false);

            CGEventPost(kCGHIDEventTap, eventDown);
            CGEventPost(kCGHIDEventTap, eventUp);

            if (resultKey == VK_BROWSER_BACK && !isFullScreen_) {
                commandUp = CGEventCreateKeyboardEvent(eventSource, kVK_Command, false);
                CGEventPost(kCGHIDEventTap, commandUp);

                CFRelease(commandDown);
                CFRelease(commandUp);
            }

            CFRelease(eventDown);
            CFRelease(eventUp);
            CFRelease(eventSource);

        }
        return true;
    }

    return false;
}