Beispiel #1
0
bool wxUIActionSimulator::MouseDblClick(int button)
{
    CGEventType downtype = CGEventTypeForMouseButton(button, true);
    CGEventType uptype = CGEventTypeForMouseButton(button, false);
    wxCFRef<CGEventRef> event(
                              CGEventCreateMouseEvent(NULL, downtype, GetMousePosition(), CGButtonForMouseButton(button)));
    
    if ( !event )
        return false;
    
    CGEventSetType(event,downtype);
    CGEventPost(tap, event);
    
    CGEventSetType(event, uptype);
    CGEventPost(tap, event);
    
    CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2);
    CGEventSetType(event, downtype);
    CGEventPost(tap, event);
    
    CGEventSetType(event, uptype);
    CGEventPost(tap, event);
    wxCFEventLoop* loop = dynamic_cast<wxCFEventLoop*>(wxEventLoop::GetActive());
    if (loop)
        loop->SetShouldWaitForEvent(true);
    
    return true;
}
Beispiel #2
0
void toggleKeyCode(MMKeyCode code, const bool down, MMKeyFlags flags)
{
#if defined(IS_MACOSX)
	CGEventRef keyEvent = CGEventCreateKeyboardEvent(NULL,
	                                                 (CGKeyCode)code, down);
	assert(keyEvent != NULL);

	CGEventSetType(keyEvent, down ? kCGEventKeyDown : kCGEventKeyUp);
	CGEventSetFlags(keyEvent, flags);
	CGEventPost(kCGSessionEventTap, keyEvent);
	CFRelease(keyEvent);
#elif defined(IS_WINDOWS)
	const DWORD dwFlags = down ? 0 : KEYEVENTF_KEYUP;

	/* Parse modifier keys. */
	if (flags & MOD_META) WIN32_KEY_EVENT_WAIT(K_META, dwFlags);
	if (flags & MOD_ALT) WIN32_KEY_EVENT_WAIT(K_ALT, dwFlags);
	if (flags & MOD_CONTROL) WIN32_KEY_EVENT_WAIT(K_CONTROL, dwFlags);
	if (flags & MOD_SHIFT) WIN32_KEY_EVENT_WAIT(K_SHIFT, dwFlags);

	win32KeyEvent(code, dwFlags);
#elif defined(USE_X11)
	Display *display = XGetMainDisplay();
	const Bool is_press = down ? True : False; /* Just to be safe. */

	/* Parse modifier keys. */
	if (flags & MOD_META) X_KEY_EVENT_WAIT(display, K_META, is_press);
	if (flags & MOD_ALT) X_KEY_EVENT_WAIT(display, K_ALT, is_press);
	if (flags & MOD_CONTROL) X_KEY_EVENT_WAIT(display, K_CONTROL, is_press);
	if (flags & MOD_SHIFT) X_KEY_EVENT_WAIT(display, K_SHIFT, is_press);

	X_KEY_EVENT(display, code, is_press);
#endif
}
Beispiel #3
0
/**
 * Special function for sending double clicks, needed for Mac OS X.
 * @param button Button to click.
 */
void doubleClick(MMMouseButton button)
{
	
#if defined(IS_MACOSX)

	/* Double click for Mac. */
	const CGPoint currentPos = CGPointFromMMPoint(getMousePos());
	const CGEventType mouseTypeDown = MMMouseToCGEventType(true, button);
	const CGEventType mouseTypeUP = MMMouseToCGEventType(false, button);

	CGEventRef event = CGEventCreateMouseEvent(NULL, mouseTypeDown, currentPos, kCGMouseButtonLeft);  
	
	/* Set event to double click. */						
	CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2);
											
	CGEventPost(kCGHIDEventTap, event);  
																
	CGEventSetType(event, mouseTypeUP);  
	CGEventPost(kCGHIDEventTap, event);  

	CFRelease(event); 

#else

	/* Double click for everything else. */
	clickMouse(button);
	microsleep(200);
	clickMouse(button);
	
#endif
}
Beispiel #4
0
Qt::Native::Status sendNativeModifierEvent_Quartz(const QNativeModifierEvent &event)
{
    CGEventRef e = CGEventCreateKeyboardEvent(0, (uint)event.nativeKeyCode, 0);
    CGEventSetType(e, kCGEventFlagsChanged);
    setModifiersFromQNativeEvent(e, event);
    CGEventPost(kCGHIDEventTap, e);
    CFRelease(e);
    return Qt::Native::Success;
}
Beispiel #5
0
void MacOSMouseOStream::doubleClick(pair<uint32_t, uint32_t> mouse, int clickCount) {
#if __APPLE__
    CGPoint point = CGPointMake(mouse.first, mouse.second);
    CGEventRef theEvent = CGEventCreateMouseEvent(
        NULL, kCGEventLeftMouseDown, point, kCGMouseButtonLeft);

    ProcessSerialNumber psn = { 0, kNoProcess };
    GetFrontProcess( &psn );

    CGEventSetIntegerValueField(theEvent, kCGMouseEventClickState, clickCount);
    CGEventPostToPSN(&psn, theEvent);
    CGEventSetType(theEvent, kCGEventLeftMouseUp);
    CGEventPostToPSN(&psn, theEvent);
    CGEventSetType(theEvent, kCGEventLeftMouseDown);
    CGEventPostToPSN(&psn, theEvent);
    CGEventSetType(theEvent, kCGEventLeftMouseUp);
    CGEventPostToPSN(&psn, theEvent);
    CFRelease(theEvent);
#endif
}
Beispiel #6
0
void os_keypress(usbdevice* kb, int scancode, int down){
    // Check for modifier keys and update flags
    int flags = 0;
    if(scancode == KEY_CAPSLOCK){
        if(down){
            if(!(kb->eflags & kCGEventFlagMaskAlphaShift))
                kb->eflags |= kCGEventFlagMaskAlphaShift;
            else
                kb->eflags &= ~kCGEventFlagMaskAlphaShift;
        }
        flags = 1;
    } else if(scancode == KEY_LEFTSHIFT || scancode == KEY_RIGHTSHIFT){
        if(down)
            kb->eflags |= kCGEventFlagMaskShift;
        else
            kb->eflags &= ~kCGEventFlagMaskShift;
        flags = 1;
    } else if(scancode == KEY_LEFTCTRL || scancode == KEY_RIGHTCTRL){
        if(down)
            kb->eflags |= kCGEventFlagMaskControl;
        else
            kb->eflags &= ~kCGEventFlagMaskControl;
        flags = 1;
    } else if(scancode == KEY_LEFTMETA || scancode == KEY_RIGHTMETA){
        if(down)
            kb->eflags |= kCGEventFlagMaskCommand;
        else
            kb->eflags &= ~kCGEventFlagMaskCommand;
        flags = 1;
    } else if(scancode == KEY_LEFTALT || scancode == KEY_RIGHTALT){
        if(down)
            kb->eflags |= kCGEventFlagMaskAlternate;
        else
            kb->eflags &= ~kCGEventFlagMaskAlternate;
        flags = 1;
    }

    CGEventRef kp;
    if(flags){
        kp = CGEventCreate(kb->event);
        CGEventSetType(kp, kCGEventFlagsChanged);
        CGEventSetIntegerValueField(kp, kCGKeyboardEventKeycode, scancode);
        kb->lastkeypress = -1;
    } else {
        kp = CGEventCreateKeyboardEvent(kb->event, scancode, down);
        kb->lastkeypress = (down ? scancode : -1);
    }
    kb->keypresstime = 0;
    CGEventSetFlags(kp, kb->eflags);
    CGEventPost(kCGHIDEventTap, kp);
    CFRelease(kp);
}
Beispiel #7
0
bool wxUIActionSimulator::MouseDragDrop(long x1, long y1, long x2, long y2,
                                        int button)
{
    CGPoint pos1,pos2;
    pos1.x = x1;
    pos1.y = y1;
    pos2.x = x2;
    pos2.y = y2;

    CGEventType downtype = CGEventTypeForMouseButton(button, true);
    CGEventType uptype = CGEventTypeForMouseButton(button, false);
    CGEventType dragtype = CGEventTypeForMouseDrag(button) ;

    wxCFRef<CGEventRef> event(
                              CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, pos1, CGButtonForMouseButton(button)));
    
    if ( !event )
        return false;
    
    CGEventSetType(event,kCGEventMouseMoved);
    CGEventPost(tap, event);
    
    CGEventSetType(event,downtype);
    CGEventPost(tap, event);
    
    
    CGEventSetType(event, dragtype);
    CGEventSetLocation(event,pos2);
    CGEventPost(tap, event);
    
    CGEventSetType(event, uptype);
    CGEventPost(tap, event);
    wxCFEventLoop* loop = dynamic_cast<wxCFEventLoop*>(wxEventLoop::GetActive());
    if (loop)
        loop->SetShouldWaitForEvent(true);
    
    return true;
}
Beispiel #8
0
bool wxUIActionSimulator::MouseDown(int button)
{
    CGEventType type = CGEventTypeForMouseButton(button, true);
    wxCFRef<CGEventRef> event(
            CGEventCreateMouseEvent(NULL, type, GetMousePosition(), button));

    if ( !event )
        return false;

    CGEventSetType(event, type);
    CGEventPost(tap, event);

    return true;
}
Beispiel #9
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;
}
Beispiel #10
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;
}
Beispiel #11
0
bool wxUIActionSimulator::MouseUp(int button)
{
    CGEventType type = CGEventTypeForMouseButton(button, false);
    wxCFRef<CGEventRef> event(
            CGEventCreateMouseEvent(NULL, type, GetMousePosition(), CGButtonForMouseButton(button)));

    if ( !event )
        return false;

    CGEventSetType(event, type);
    CGEventPost(tap, event);
    wxCFEventLoop* loop = dynamic_cast<wxCFEventLoop*>(wxEventLoop::GetActive());
    if (loop)
        loop->SetShouldWaitForEvent(true);
    
    return true;
}
Beispiel #12
0
bool UIEventSimulator::MouseMove(long x, long y)
{
    CGPoint pos;
    pos.x = x;
    pos.y = y;
    CGEventType type = kCGEventMouseMoved;
    CGEventRef event = CGEventCreateMouseEvent(NULL, type, pos, kCGMouseButtonLeft);
    CGEventSetType(event, type);
    
    if (event)
    {
        CGEventPost(tap, event);
    }
    CFRelease(event);
    
    return true;
}
Beispiel #13
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
}
Beispiel #14
0
bool wxUIActionSimulator::MouseMove(long x, long y)
{
    CGPoint pos;
    pos.x = x;
    pos.y = y;

    CGEventType type = kCGEventMouseMoved;
    wxCFRef<CGEventRef> event(
            CGEventCreateMouseEvent(NULL, type, pos, kCGMouseButtonLeft));

    if ( !event )
        return false;

    CGEventSetType(event, type);
    CGEventPost(tap, event);

    return true;
}
Beispiel #15
0
bool UIEventSimulator::MouseDown(int button)
{
    CGPoint pos;
    int x, y;
    wxGetMousePosition(&x, &y); 
    pos.x = x;
    pos.y = y;
    CGEventType type = CGEventTypeForMouseButton(button, true);
    CGEventRef event = CGEventCreateMouseEvent(NULL, type, pos, button);
    CGEventSetType(event, type);
    
    if (event)
    {
        CGEventPost(tap, event);
    }
    CFRelease(event);
    return true;
}
Beispiel #16
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
}
Beispiel #17
0
void mouseClick(const QPoint &globalPos, Qt::MouseButtons buttons)
{
    CGPoint position;
    position.x = globalPos.x();
    position.y = globalPos.y();

    CGEventType mouseDownType = (buttons & Qt::LeftButton) ? kCGEventLeftMouseDown :
                                (buttons & Qt::RightButton) ? kCGEventRightMouseDown :
                                kCGEventOtherMouseDown;
    CGMouseButton mouseButton = mouseDownType == kCGEventOtherMouseDown ? kCGMouseButtonCenter : kCGEventLeftMouseDown;
    CGEventRef mouseEvent = CGEventCreateMouseEvent(NULL, mouseDownType, position, mouseButton);
    CGEventPost(kCGHIDEventTap, mouseEvent);

    CGEventType mouseUpType = (buttons & Qt::LeftButton) ? kCGEventLeftMouseUp :
                              (buttons & Qt::RightButton) ? kCGEventRightMouseUp :
                              kCGEventOtherMouseUp;
    CGEventSetType(mouseEvent, mouseUpType);
    CGEventPost(kCGHIDEventTap, mouseEvent);
    CFRelease(mouseEvent);
}
Beispiel #18
0
bool wxUIActionSimulator::MouseMove(long x, long y)
{
    CGPoint pos;
    pos.x = x;
    pos.y = y;

    CGEventType type = kCGEventMouseMoved;
    wxCFRef<CGEventRef> event(
            CGEventCreateMouseEvent(NULL, type, pos, kCGMouseButtonLeft));

    if ( !event )
        return false;

    CGEventSetType(event, type);
    CGEventPost(tap, event);

    wxCFEventLoop* loop = dynamic_cast<wxCFEventLoop*>(wxEventLoop::GetActive());
    if (loop)
        loop->SetShouldWaitForEvent(true);
    
    return true;
}
Beispiel #19
0
   void mouseClick(const QPoint &globalPos, Qt::MouseButtons buttons)
    {
        CGPoint position;
        position.x = globalPos.x();
        position.y = globalPos.y();

        CGEventType mouseDownType = (buttons & Qt::LeftButton) ? kCGEventLeftMouseDown :
                                    (buttons & Qt::RightButton) ? kCGEventRightMouseDown :
                                                                  kCGEventOtherMouseDown;
        // The mouseButton argument to CGEventCreateMouseEvent() is ignored unless the type
        // is kCGEventOtherMouseDown, so defaulting to kCGMouseButtonLeft is fine.
        CGMouseButton mouseButton = mouseDownType == kCGEventOtherMouseDown ? kCGMouseButtonCenter : kCGMouseButtonLeft;
        CGEventRef mouseEvent = CGEventCreateMouseEvent(NULL, mouseDownType, position, mouseButton);
        CGEventPost(kCGHIDEventTap, mouseEvent);

        CGEventType mouseUpType = (buttons & Qt::LeftButton) ? kCGEventLeftMouseUp :
                                  (buttons & Qt::RightButton) ? kCGEventRightMouseUp :
                                                                kCGEventOtherMouseUp;
        CGEventSetType(mouseEvent, mouseUpType);
        CGEventPost(kCGHIDEventTap, mouseEvent);
        CFRelease(mouseEvent);
    }
Beispiel #20
0
void
COSXScreen::fakeMouseButton(ButtonID id, bool press)
{
	NXEventHandle handle = NXOpenEventStatus();
	double clickTime = NXClickTime(handle);
	
	if ((ARCH->time() - m_lastDoubleClick) <= clickTime) {
		// drop all down and up fakes immedately after a double click.
		// TODO: perhaps there is a better way to do this, usually in
		// finder, if you tripple click a folder, it will open it and
		// then select a folder under the cursor -- and perhaps other
		// strange behaviour might happen?
		LOG((CLOG_DEBUG1 "dropping mouse button %s",
			press ? "press" : "release"));
		return;
	}
	
	// Buttons are indexed from one, but the button down array is indexed from zero
	UInt32 index = id - kButtonLeft;
	if (index >= NumButtonIDs) {
		return;
	}
	
	CGPoint pos;
	if (!m_cursorPosValid) {
		SInt32 x, y;
		getCursorPos(x, y);
	}
	pos.x = m_xCursor;
	pos.y = m_yCursor;

	// variable used to detect mouse coordinate differences between
	// old & new mouse clicks. Used in double click detection.
	SInt32 xDiff = m_xCursor - m_lastSingleClickXCursor;
	SInt32 yDiff = m_yCursor - m_lastSingleClickYCursor;
	double diff = sqrt(xDiff * xDiff + yDiff * yDiff);
	// max sqrt(x^2 + y^2) difference allowed to double click
	// since we don't have double click distance in NX APIs
	// we define our own defaults.
	const double maxDiff = sqrt(2) + 0.0001;

	if (press && (id == kButtonLeft) &&
		((ARCH->time() - m_lastSingleClick) <= clickTime) &&
		diff <= maxDiff) {

		LOG((CLOG_DEBUG1 "faking mouse left double click"));
		
		// finder does not seem to detect double clicks from two separate
		// CGEventCreateMouseEvent calls. so, if we detect a double click we
		// use CGEventSetIntegerValueField to tell the OS.
		// 
		// the caveat here is that findor will see this as a single click 
		// followed by a double click (even though there should be only a
		// double click). this may cause weird behaviour in other apps.
		//
		// for some reason using the old CGPostMouseEvent function, doesn't
		// cause double clicks (though i'm sure it did work at some point).
		
		CGEventRef event = CGEventCreateMouseEvent(
			NULL, kCGEventLeftMouseDown, pos, kCGMouseButtonLeft);
		
		CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2);
		m_buttonState.set(index, kMouseButtonDown);
		CGEventPost(kCGHIDEventTap, event);
		
		CGEventSetType(event, kCGEventLeftMouseUp);
		m_buttonState.set(index, kMouseButtonUp);
		CGEventPost(kCGHIDEventTap, event);
		
		CFRelease(event);
	
		m_lastDoubleClick = ARCH->time();
	}
	else {
		
		// ... otherwise, perform a single press or release as normal.
		
		MouseButtonState state = press ? kMouseButtonDown : kMouseButtonUp;
		
		LOG((CLOG_DEBUG1 "faking mouse button %s", press ? "press" : "release"));
		
		MouseButtonEventMapType thisButtonMap = MouseButtonEventMap[index];
		CGEventType type = thisButtonMap[state];
		
		CGEventRef event = CGEventCreateMouseEvent(NULL, type, pos, index);
	
		m_buttonState.set(index, state);
		CGEventPost(kCGHIDEventTap, event);
		
		CFRelease(event);
	
		m_lastSingleClick = ARCH->time();
		m_lastSingleClickXCursor = m_xCursor;
		m_lastSingleClickYCursor = m_yCursor;
	}
}
Beispiel #21
0
int main( int argc, char ** argv)
{
	CGSize mainScreenSize = CGDisplayScreenSize (CGMainDisplayID ());
	CGDirectDisplayID currentDisplayID = CGMainDisplayID ();
	CGSize currentDisplaySize = mainScreenSize;
	CGRect displayRect;
	CGPoint newloc;
	Point pt;
	CGEventRef eventRef;
	
	InputEvent event;
	pInputEvent pEvent = &event;

	SOCKET s, s_accept;
	struct sockaddr_in s_add; //from anyone!
	struct sockaddr s_client;
	socklen_t s_client_size = sizeof( struct sockaddr );
	int port = PORT;
	int recvsize;
	char reuse = 1;//SO_REUSEADDR

	int xDelta=0, yDelta=0;

//network stuff
	//configure socket
	if ( ( s = socket( PF_INET, SOCK_STREAM, 0 ) ) == -1 ) 
	{
		perror ( "Failed to create socket :(" ); 
		exit( 2 );

	}

	if ( setsockopt( s, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof( reuse ) ) == -1 )
	{
		perror( "Failed to set reuseaddr! Trying to continue..." );
	}

	memset( &s_add, 0, sizeof( struct sockaddr_in ) );
	s_add.sin_family = AF_INET;
	s_add.sin_port = htons( port );
	s_add.sin_addr.s_addr = INADDR_ANY;

	if ( bind( s, (struct sockaddr * )&s_add, sizeof( struct sockaddr_in ) ) == -1 )
	{
		perror( "Failed to bind socket" );
		exit( 2 );
	}

	if( listen( s , 1 ) )
	{
		perror( "Can't listen!" );
		exit( 2 );
	}

	while( 1 )
	{

		s_accept = accept( s, &s_client, &s_client_size );

		if ( s_accept == -1 )
		{
			perror( "failed to accept!" );
			return -1;
		}

		while( 1 )
		{
			recvsize = recv( s_accept, pEvent, sizeof( InputEvent ), MSG_WAITALL );
			if ( recvsize == sizeof( InputEvent ) )//got data
			{

				switch( pEvent->event_t )
				{
					case EVENT_TYPE_MOUSE_MOVE:
						if(debug) printf("Mouse move\n");
						GetGlobalMouse( &pt );//get cursor pos
						//update x/y
						
						newloc.x = pt.h + pEvent->move_info.dx * 2;
						newloc.y = pt.v + pEvent->move_info.dy * 2;
						
						CGDisplayCount displayCount = 0;
						//check if we've crossed outside the x bounds
						
						CGDirectDisplayID tempDisplayID;
						
						CGGetDisplaysWithPoint (
							newloc,
							1,
							&tempDisplayID,
							&displayCount);
							
						
						if (displayCount != 0) {
							currentDisplayID = tempDisplayID;
						}
						
						displayRect = CGDisplayBounds(currentDisplayID);
						
						if (newloc.x < displayRect.origin.x) {
							newloc.x = displayRect.origin.x;
						}
						else if (newloc.x > displayRect.origin.x +
								 displayRect.size.width - 1) {
							newloc.x = displayRect.origin.x + displayRect.size.width - 1;
						}
						if (newloc.y < displayRect.origin.y) {
							newloc.y = displayRect.origin.y;
						}
						else if (newloc.y > displayRect.origin.y +
								 displayRect.size.height - 1) {
							newloc.y = displayRect.origin.y + displayRect.size.height - 1;
						}
												
						if(debug) 
						{
							printf("Current mouse location: {%d,%d}\n", pt.h, pt.v);
							printf("newloc: {%f,%f}\n", newloc.x, newloc.y);
							printf("Screen size: {%f,%f}\n", currentDisplaySize.width, currentDisplaySize.height);
							fflush( stdout );
						}
						//CGPostMouseEvent( newloc, true /*yes move there*/, 0 , false); 
						
						eventRef = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, newloc,
																   kCGMouseButtonCenter);
						CGEventSetType(eventRef, kCGEventMouseMoved); // Apple bug... need to set the type manually
											
						CGEventPost(kCGSessionEventTap, eventRef);
						CFRelease(eventRef);
						break;

					case EVENT_TYPE_MOUSE_SCROLL_MOVE:
						if(debug) 
						{
							printf( "Scrolling\n" );
							fflush( stdout );
						}
						
						xDelta += pEvent->move_info.dx;
						yDelta += pEvent->move_info.dy;

						//TODO: mac osx has a api to get the exact scroll amount, look into that
						if ( ( yDelta/SCROLL_AMT != 0 )  || ( xDelta/SCROLL_AMT != 0 ) )
						{//if any clicks need to be made...
							
							//send the number of whole clicks....
							CGPostScrollWheelEvent( 2, -yDelta/SCROLL_AMT, -xDelta/SCROLL_AMT ); 

							//remove them from our counter
							xDelta %=SCROLL_AMT;
							yDelta %=SCROLL_AMT;
						}

						break;
					case EVENT_TYPE_MOUSE_DOWN:
						if(debug) printf("Mouse down\n");
						GetGlobalMouse( &pt );//get cursor pos
						//update x/y
						
						
						
						if(debug) 
						{
							printf("Current mouse location: {%d,%d}", pt.h, pt.v);
							fflush( stdout );
						}
						//CGPostMouseEvent( newloc, true /*yes move there*/, 0 , false); 
						
						newloc.x = pt.h;
						newloc.y = pt.v;
						
						eventRef = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown , newloc,
																   kCGMouseButtonCenter);
						CGEventSetType(eventRef, kCGEventLeftMouseDown); // Apple bug... need to set the type manually
											
						CGEventPost(kCGSessionEventTap, eventRef);
						CFRelease(eventRef);
						break;

					case EVENT_TYPE_MOUSE_UP:	
						if(debug) printf("Mouse up\n");
						GetGlobalMouse( &pt );//get cursor pos
						//update x/y
						
						
						
						if(debug) 
						{
							printf("Current mouse location: {%d,%d}", pt.h, pt.v);
							fflush( stdout );
						}
						//CGPostMouseEvent( newloc, true /*yes move there*/, 0 , false); 
						
						newloc.x = pt.h;
						newloc.y = pt.v;
						
						eventRef = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseUp , newloc,
																   kCGMouseButtonCenter);
						CGEventSetType(eventRef, kCGEventLeftMouseUp); // Apple bug... need to set the type manually
											
						CGEventPost(kCGSessionEventTap, eventRef);
						CFRelease(eventRef);
						break;

					/* TODO:
					 * so far this will only work for basic keycodes, and will probably fail on anything non-ascii,
					 * and that has yet to be tested, etc.  Right now I'm mostly interested in having the events properly
					 * generated and support ascii keys.  We will handle the rest later.
					 */
					case EVENT_TYPE_KEY_DOWN:
						if ( debug )
						{
							printf( "Key down: %c\n", pEvent->key_info.keycode );
							fflush( stdout );
						}

						eventRef = CGEventCreateKeyboardEvent( NULL, (CGKeyCode)( pEvent->key_info.keycode - 1 ), true );

						CGEventSetType( eventRef, kCGEventKeyDown );

						CGEventPost( kCGSessionEventTap, eventRef );
						CFRelease( eventRef );
						break;

					case EVENT_TYPE_KEY_UP:
						if ( debug )
						{
							printf( "Key Up: %c\n", pEvent->key_info.keycode );
							fflush( stdout );
						}

						eventRef = CGEventCreateKeyboardEvent( NULL, (CGKeyCode)( pEvent->key_info.keycode - 1 ), false );

						CGEventSetType( eventRef, kCGEventKeyUp );

						CGEventPost( kCGSessionEventTap, eventRef );
						CFRelease( eventRef );
						break;

					default:
						fprintf( stderr, "unknown message type: %d\n", pEvent->event_t );
						fflush( stdout );
						break;
				}

				//flush events, if needed in macosx
			
			}
			else if ( recvsize > 0 )
			{
				fprintf( stderr, "partial recv!" );
			}
			else if ( recvsize == 0 )
			{
				//connection terminated
				close( s_accept );
				break; //exit this while loop, wait for another connection
			}
			else
			{
				perror( "error in recv" );
			}
		}

	}

	//shouldn't get here!

	return 0;
}
void QGeneralSettingWidget::TPDP_OnGST(T3K_DEVICE_INFO /*devInfo*/, ResponsePart /*Part*/, unsigned short /*ticktime*/, const char */*partid*/,
                                       unsigned char /*cActionGroup*/, unsigned char cAction, unsigned short /*wFeasibleness*/,
                                       unsigned short /*x*/, unsigned short /*y*/, unsigned short /*w*/, unsigned short /*h*/, float fZoom, const char */*msg*/)
{
    if( cAction == t3kgstNoAction || (fZoom == 0.0f || fZoom == 1.0f) /*|| cAction != t3kgstFingersMove*/ )
    {
        if( g_fZoom != 0.0f && g_fZoom != 1.0f )
        {
            // end gesture
            CGEventRef e = CGEventCreate(NULL);
            CGEventSetType(e, 0x1D);
            CGEventSetFlags(e, 0x100);

            CGEventSetTimestamp(e, 0);
            CGEventSetIntegerValueField(e, 0x6E, 0x3E);
            CGEventSetIntegerValueField(e, 0x75, 0x00);
            CGEventPost(kCGHIDEventTap, e);

            CFRelease(e);

            g_fZoom = 0.0f;

            qDebug() << "end gesture";
        }
    }
    else if( fZoom != 0.0f && fZoom != 1.0f )
    {
        CGEventRef e = CGEventCreate(NULL);
        CGEventSetType(e, 0x1D);
        CGEventSetFlags(e, 0x100);

        if( g_fZoom == 0.0f || g_fZoom == 1.0f )
        {
            g_fZoom = fZoom;
            qDebug() << "begin gesture : " << g_fZoom;
            CGEventSetTimestamp(e, 0);
            CGEventSetIntegerValueField(e, 0x6E, 0x3D);
            CGEventSetIntegerValueField(e, 0x75, 0x08);
            CGEventPost(kCGHIDEventTap, e);
        }
        else
        {
            float dZoom = g_fZoom - fZoom;
            qDebug() << "=== " << g_fZoom << " " << fZoom << " changed Zoom : " << dZoom;
            if( qAbs(dZoom) >= 0.02 && qAbs(dZoom) <= 0.05 )
            {
                CGEventSetTimestamp(e, 0);
                CGEventSetIntegerValueField(e, 0x6E, 0x08);
                CGEventSetDoubleValueField(e, 0x71, -dZoom);
                CGEventPost(kCGHIDEventTap, e);
            }

            g_fZoom = fZoom;
        }

        CFRelease(e);
    }

    qDebug() << "Zoom : " << fZoom << " " << cAction;
//    qDebug() << QString("Gesture : AG(%1), A(%2), F(%3), X(%4), Y(%5), W(%6), H(%7), ZOOM(%8), MSG(%9)").arg(cActionGroup).arg(cAction).arg(wFeasibleness)
//            .arg(x).arg(y).arg(w).arg(h).arg(fZoom).arg(msg);
}
//--------------------------------------------------------------
void MouseThread::postEvent(CGEventType type, int x, int y, CGMouseButton button) {
  CGEventRef event = CGEventCreateMouseEvent(NULL, type, CGPointMake(x, y), button);
  CGEventSetType(event, type);
  CGEventPost(kCGHIDEventTap, event);
  CFRelease(event);
}
Beispiel #24
0
void verticalScroll(int x, int y) {
	CGEventRef event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 2, y, x);
	CGEventSetType(event, kCGEventScrollWheel);
	CGEventPost(kCGSessionEventTap, event);
	CFRelease(event);
}