static inline CGPoint GetMouseLoc()
{
	CGEventRef ourEvent = CGEventCreate(NULL);
	CGPoint point = CGEventGetLocation(ourEvent);
    CFRelease(ourEvent);
    return point;
}
int MouseTool::GetMouseState(int *x, int *y){
    int _x, _y;
    int state=0;
    #ifdef __APPLE__
        CGEventRef event = CGEventCreate(NULL);
        CGPoint cursor = CGEventGetLocation(event);
        CFRelease(event);
        if(CGEventSourceButtonState(0, kCGMouseButtonLeft)) state |= MT_LBUTTON;
        if(CGEventSourceButtonState(0, kCGMouseButtonRight)) state |= MT_RBUTTON;
        if(CGEventSourceButtonState(0, kCGMouseButtonCenter)) state |= MT_MBUTTON;
        _x = cursor.x;
        _y = cursor.y;
    #elif __WIN32__
        POINT point;
        GetCursorPos(&point);
        _x = point.x;
        _y = point.y;
        //printf("%d %d %d\n",!(GetAsyncKeyState(VK_RBUTTON) & 1<<16),GetAsyncKeyState(VK_MBUTTON),GetKeyState(VK_LBUTTON));
        if(GetAsyncKeyState(VK_RBUTTON) & 1 << 16) state |= MT_RBUTTON;
        if(GetAsyncKeyState(VK_MBUTTON) & 1 << 16) state |= MT_MBUTTON;
        if(GetAsyncKeyState(VK_LBUTTON) & 1 << 16) state |= MT_LBUTTON;
    #else
        XEvent evt;
        XQueryPointer(dpy, root_window, &evt.xbutton.root, &evt.xbutton.root, &_x, &_y, &evt.xbutton.x, &evt.xbutton.y, &evt.xbutton.state);
        if(evt.xbutton.state & Button1Mask) state |= MT_RBUTTON;
        if(evt.xbutton.state & Button2Mask) state |= MT_MBUTTON;
        if(evt.xbutton.state & Button3Mask) state |= MT_LBUTTON;
    #endif
    if(x != NULL) *x = _x;
    if(y != NULL) *y = _y;
    return state;
}
void interrupt_callback (void *target, IOReturn result, void *refcon,
                         void *sender, uint32_t bufferSize) {
    static int interrupt_counter = 0;
    HIDDataRef hidDataRef = (HIDDataRef) refcon;
    char hw_x = SCHAR_MAX, hw_y = SCHAR_MAX; /* hardware coordinates, received from mouse */
    int sw_x = INT_MAX, sw_y = INT_MAX;      /* software coordinates, grabbed from system mouse location */

    if (!hidDataRef) {
        return;
    }

    if (bufferSize < 4) {
        return;
    }

    CGEventRef event = CGEventCreate (NULL);
    CGPoint point = CGEventGetLocation(event);

    sw_x = point.x - point0.x;
    sw_y = point.y - point0.y;
    point0.x = point.x;
    point0.y = point.y;

    if (interrupt_counter > 0) {
        printf("         sw: %3i  x %3i\n", sw_x, sw_y);
    }

    hw_x = (char) hidDataRef->buffer[1];
    hw_y = (char) hidDataRef->buffer[2];

    printf("hw: %3i  x %3i", hw_x, hw_y);

    interrupt_counter++;
}
Beispiel #4
0
// Quartz event tap support for the secondary display. This make sure that we 
// will show the cursor if a local event comes in while synergy has the cursor off the screen.
CGEventRef
COSXScreen::handleCGInputEventSecondary(CGEventTapProxy proxy,
							   CGEventType type,
							   CGEventRef event,
							   void* refcon)
{
       COSXScreen* screen = (COSXScreen*)refcon;
       if (screen->m_cursorHidden) {
                CGPoint pos;
                bool showCursor = true;
                if (type == kCGEventMouseMoved) {
                        pos = CGEventGetLocation(event);
                        if (pos.x == screen->m_xCenter && pos.y == screen->m_yCenter) {
                                showCursor = false;
                        }
                }
                if (showCursor) {
                        LOG((CLOG_DEBUG "Trying to show cursor from local event. (type = %d)", type));
                        screen->showCursor();
                        screen->m_cursorHidden = false;
                }
        }
        LOG((CLOG_DEBUG2 "Local event? (type = %d)", type));
        return event;
}
Beispiel #5
0
INLINE MMPoint getMousePos()
{
#if defined(IS_MACOSX)
	CGEventRef event = CGEventCreate(NULL);
	CGPoint point = CGEventGetLocation(event);
	CFRelease(event);

	return MMPointFromCGPoint(point);
#elif defined(USE_X11)
	int x, y; /* This is all we care about. Seriously. */
	Window garb1, garb2; /* Why you can't specify NULL as a parameter */
	int garb_x, garb_y;  /* is beyond me. */
	unsigned int more_garbage;

	Display *display = XGetMainDisplay();
	XQueryPointer(display, XDefaultRootWindow(display), &garb1, &garb2,
	              &x, &y, &garb_x, &garb_y, &more_garbage);

	return MMPointMake(x, y);
#elif defined(IS_WINDOWS)
	POINT point;
	GetCursorPos(&point);

	return MMPointFromPOINT(point);
#endif
}
Beispiel #6
0
CGPoint
mouse_current_position()
{
  CGEventRef event = CGEventCreate(nil);
  CGPoint point = CGEventGetLocation(event);
  RELEASE(event);
  return point;
}
Beispiel #7
0
static QPoint getMouseLocationFromQuartzEvent(CGEventRef inEvent)
{
    CGPoint pos = CGEventGetLocation(inEvent);
    QPoint tmp;
    tmp.setX(pos.x);
    tmp.setY(pos.y);
    return tmp;
}
Beispiel #8
0
internal CGPoint
GetCursorPos()
{
    CGEventRef Event = CGEventCreate(NULL);
    CGPoint Cursor = CGEventGetLocation(Event);
    CFRelease(Event);

    return Cursor;
}
Beispiel #9
0
int main(int argc, char *argv[]){

  float maxX = atoi(argv[1]);
  float maxY = atoi(argv[2]);

  Mahalo *m = new Mahalo();
  m->setup();

  float tones[16] = { C4, Csharp4, D4, Dsharp4, 
                      E4, F5, Fsharp5, G5,
                      Gsharp5, A5, Asharp5, B5,
                      C6, Csharp6, D6, Dsharp6 };

  Wave *waves[16];

  SampleMixer *mix = new SampleMixer();
  for(int i = 0; i < 16; i++){
    waves[i] = new Wave(tones[i],m->getRate(),0.0);
    mix->Add(waves[i]);
  }
  
  m->setSampleSource(mix); 
  
  m->sstart();

  int fd;
  unsigned char n[3];
  int which = 0;
  unsigned delay = 0;
  float level = 0.0;
  unsigned freq;

  fd = open(argv[1],O_RDONLY);
  while( read(fd,n,3) ){

      CGEventRef event = CGEventCreate(NULL);
      CGPoint cursor = CGEventGetLocation(event);
      CFRelease(event);
      fprintf(stderr,"%f %f\n",cursor.x, cursor.y);
 
      delay = (int)((cursor.y / maxY) * 1000); 
      freq = (int)((cursor.x / maxX) * 16);

      waves[freq]->setAmpVal(1.0 - (cursor.y / maxY));
      usleep(delay);
      waves[freq]->setAmpVal(0.0);
      usleep(3000);

  }


  usleep(5000000);

  m->sstop();
}
Beispiel #10
0
int
main(int argc, char **argv)
{
    
    CGEventRef ourEvent = CGEventCreate(NULL);
    CGPoint ourLoc = CGEventGetLocation(ourEvent);
    
    CFRelease(ourEvent);
    
    
    printf("%5.0f,%5.0f\n",
               (float)ourLoc.x, (float)ourLoc.y);
   
    exit(0);
}
Beispiel #11
0
void detect_window_below_cursor()
{
        window_lst.clear();

        CFArrayRef osx_window_list = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
        if(osx_window_list)
        {
                CFIndex osx_window_count = CFArrayGetCount(osx_window_list);
                for(CFIndex i = 0; i < osx_window_count; ++i)
                {
                        CFDictionaryRef elem = (CFDictionaryRef)CFArrayGetValueAtIndex(osx_window_list, i);
                        window_lst.push_back(app_info());
                        CFDictionaryApplyFunction(elem, print_keys, NULL);
                }

                CGEventRef event = CGEventCreate(NULL);
                CGPoint cursor = CGEventGetLocation(event);
                CFRelease(event);

                std::cout << "Mouse Pos: " << cursor.x << ", " << cursor.y << std::endl;
                for(int i = 0; i < window_lst.size(); ++i)
                {
                        if(window_lst[i].layer == 0)
                        {
                                if(cursor.x >= window_lst[i].x && cursor.x <= window_lst[i].x + window_lst[i].width
                                                && cursor.y >= window_lst[i].y && cursor.y <= window_lst[i].y + window_lst[i].height)
                                {
                                        window_lst_focus_index = i;
                                        pid = window_lst[i].pid;
                                        GetProcessForPID(pid, &psn);
                                        SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly);
                                        break;
                                }

                                std::cout << "Owner: " << window_lst[i].owner << std::endl;
                                std::cout << "Name: " << window_lst[i].name << std::endl;
                                std::cout << "PID: " << window_lst[i].pid << std::endl;
                                std::cout << "Layer: " << window_lst[i].layer << std::endl;
                                std::cout << "X: " << window_lst[i].x << std::endl;
                                std::cout << "Y: " << window_lst[i].y << std::endl;
                                std::cout << "Width: " << window_lst[i].width << std::endl;
                                std::cout << "Height: " << window_lst[i].height << std::endl;

                        }
                }
                std::cout << "Keyboard focus: " << pid << std::endl;
        }
}
Beispiel #12
0
int main() {
	int keyCode = 49; //space bar
	srand ( time(NULL) );
	printf("User input coming in 30 seconds\n");
	sleep(27);
	printf("3...\n");
	sleep(1);
	printf("2...\n");
	sleep(1);
	printf("1...\n");
	sleep(1);
	printf("NOW!");
	while(1){
		CGEventRef ourEvent = CGEventCreate(NULL);
		CGPoint point = CGEventGetLocation(ourEvent);
		
	    CGEventRef click1_down = CGEventCreateMouseEvent(
	        NULL, kCGEventLeftMouseDown,
	        point,
	        kCGMouseButtonLeft
	    );
	    CGEventRef click1_up = CGEventCreateMouseEvent(
	        NULL, kCGEventLeftMouseUp,
	        point,
	        kCGMouseButtonLeft
	    );
		
	    CGEventPost(kCGHIDEventTap, click1_down);
	    sleep(0.11);			
	    CGEventPost(kCGHIDEventTap, click1_up);
		
		CFRelease(click1_up);
	    CFRelease(click1_down);
		CFRelease(ourEvent);
		
		sleep(0.89);
		if(rand() % 100 <= 2){	//2% chance
			CGEventRef e = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)keyCode, true);
			CGEventPost(kCGSessionEventTap, e);
			CFRelease(e);
			e = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)keyCode, false);
			CGEventPost(kCGSessionEventTap, e);		
			CFRelease(e);
		}
		sleep(9);
	}
}
Beispiel #13
0
screen_info *GetDisplayOfMousePointer()
{
    CGEventRef Event = CGEventCreate(NULL);
    CGPoint Cursor = CGEventGetLocation(Event);
    CFRelease(Event);

    std::map<unsigned int, screen_info>::iterator It;
    for(It = DisplayMap.begin(); It != DisplayMap.end(); ++It)
    {
        screen_info *Screen = &It->second;
        if(Cursor.x >= Screen->X && Cursor.x <= Screen->X + Screen->Width &&
           Cursor.y >= Screen->Y && Cursor.y <= Screen->Y + Screen->Height)
               return Screen;
    }

    return NULL;
}
Beispiel #14
0
/**
 * Calculate the delta for a mouse move and add them to the event.
 * @param event The mouse move event (by ref).
 * @param point The new mouse x and y.
 */
void calculateDeltas(CGEventRef *event, MMPoint point)
{
	/**
	 * The next few lines are a workaround for games not detecting mouse moves.
	 * See this issue for more information:
	 * https://github.com/octalmage/robotjs/issues/159
	 */
	CGEventRef get = CGEventCreate(NULL);
	CGPoint mouse = CGEventGetLocation(get);

	// Calculate the deltas.
	int64_t deltaX = point.x - mouse.x;
	int64_t deltaY = point.y - mouse.y;

	CGEventSetIntegerValueField(*event, kCGMouseEventDeltaX, deltaX);
	CGEventSetIntegerValueField(*event, kCGMouseEventDeltaY, deltaY);

	CFRelease(get);
}
Beispiel #15
0
void
infoDisplays(void)
{
    CGDisplayErr      dErr;
    CGDisplayCount    displayCount, i;
    CGDirectDisplayID mainDisplay;
    CGDisplayCount    maxDisplays = MAX_DISPLAYS;
    CGDirectDisplayID onlineDisplays[MAX_DISPLAYS];
    
    CGEventRef ourEvent = CGEventCreate(NULL);
    CGPoint ourLoc = CGEventGetLocation(ourEvent);
    
    CFRelease(ourEvent);
    
    mainDisplay = CGMainDisplayID();
   
    dErr = CGGetOnlineDisplayList(maxDisplays, onlineDisplays, &displayCount);
    if (dErr != kCGErrorSuccess) {
        fprintf(stderr, "CGGetOnlineDisplayList: error %d.\n", dErr);
        exit(1);
    }
   
    printf("#  Display_ID  Resolution  ____Display_Bounds____  Rotation\n");
    for (i = 0; i < displayCount; i++) {
        CGDirectDisplayID dID = onlineDisplays[i];
        printf("%-2d %10p  %4lux%-4lu  %5.0f %5.0f %5.0f %5.0f    %3.0f    %s%s%s", 
               CGDisplayUnitNumber (dID), dID,
               CGDisplayPixelsWide(dID), CGDisplayPixelsHigh(dID),
               CGRectGetMinX (CGDisplayBounds (dID)),
               CGRectGetMinY (CGDisplayBounds (dID)),
               CGRectGetMaxX (CGDisplayBounds (dID)),
               CGRectGetMaxY (CGDisplayBounds (dID)),           
               CGDisplayRotation (dID),
               (CGDisplayIsActive (dID)) ? "" : "[inactive]",
               (dID == mainDisplay) ? "[main]" : "",
               (CGDisplayIsBuiltin (dID)) ? "[internal]\n" : "\n");
    }
    
    printf("Mouse Cursor Position:  ( %5.0f , %5.0f )\n",
               (float)ourLoc.x, (float)ourLoc.y);
   
    exit(0);
}
Beispiel #16
0
Purity::Vector2i Purity::Mouse::getPosition()
{
    Vector2i ret(0,0);
    
#ifdef __gnu_linux__
    // Open a connection with the X server
    Display* display = XOpenDisplay(NULL);

    // we don't care about these but they are required
    ::Window root, child;
    int x, y;
    unsigned int buttons;

    int gx = 0;
    int gy = 0;

    XQueryPointer(display, DefaultRootWindow(display), &root, &child, &gx, &gy, &x, &y, &buttons);

    // Close the connection with the X server
    XCloseDisplay(display);

    ret.x = gx;
    ret.y = gy;
#elif defined _WIN32
    POINT point;
    GetCursorPos(&point);
    
    ret.x = point.x;
    ret.y = point.y;
#elif defined __APPLE__ && !(TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
    auto event = CGEventCreate(nullptr);
    auto cursor = CGEventGetLocation(event);
    
    ret.x = cursor.x;
    ret.y = cursor.y;
    
    CFRelease(event);
#endif
    
    return ret;
}
FREObject setCursorPos(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
    int tx = 0;
    int ty = 0;
    FREGetObjectAsInt32(argv[0], &tx);
    FREGetObjectAsInt32(argv[1], &ty);

    //as3Print("Set cursor pos \n");//,tx,ty);

    CGPoint point;
    point.x = tx;
    point.y = ty;

    CGAssociateMouseAndMouseCursorPosition(true);
    
    //CGWarpMouseCursorPosition(point);
   // printf("Error : %i\n",error);
    CGDisplayMoveCursorToPoint(CGMainDisplayID(),point);

    CGAssociateMouseAndMouseCursorPosition(true);
    CGEventRef mouse = CGEventCreateMouseEvent (NULL, kCGEventMouseMoved, CGPointMake(tx, ty),0);
    CGEventPost(kCGHIDEventTap, mouse);
    CFRelease(mouse);
    
    
    CGEventRef event = CGEventCreate(NULL);
    CGPoint cursorGet = CGEventGetLocation(event);
    CFRelease(event);
    
    
    
    char msg[256];
    sprintf(msg,"After set, check pos %f %f\n",cursorGet.x, cursorGet.y);
    //as3Print(msg);
    
    FREObject result;
    FRENewObjectFromBool(1, &result);
    //FRENewObjectFromBool(true,&result);
    return result;
}
Beispiel #18
0
// Event helpers
static void postevent(io_connect_t event, UInt32 type, NXEventData* ev, IOOptionBits flags, IOOptionBits options, int silence_errors){
    // Hack #1: IOHIDPostEvent will fail with kIOReturnNotPrivileged if the event doesn't originate from the UID that owns /dev/console
    // You'd think being root would be good enough. You'd be wrong. ckb-daemon needs to run as root for other reasons though
    // (namely, being able to seize the physical IOHIDDevices) so what we do instead is change our EUID to the appropriate owner,
    // post the event, and then change it right back.
    // Yeah...
    uid_t uid = 0;
    gid_t gid = 0;
    struct stat file;
    if(!stat("/dev/console", &file)){
        uid = file.st_uid;
        gid = file.st_gid;
    }
    euid_guard_start;
    if(uid != 0)
        seteuid(uid);
    if(gid != 0)
        setegid(gid);

    IOGPoint location = {0, 0};
    if((options & kIOHIDSetRelativeCursorPosition) && type != NX_MOUSEMOVED){
        // Hack #2: IOHIDPostEvent will not accept relative mouse coordinates for any event other than NX_MOUSEMOVED
        // So we need to get the current absolute coordinates from CoreGraphics and then modify those...
        CGEventRef cge = CGEventCreate(nil);
        CGPoint loc = CGEventGetLocation(cge);
        CFRelease(cge);
        location.x = floor(loc.x + ev->mouseMove.dx);
        location.y = floor(loc.y + ev->mouseMove.dy);
        options = (options & ~kIOHIDSetRelativeCursorPosition) | kIOHIDSetCursorPosition;
    }
    kern_return_t res = IOHIDPostEvent(event, type, location, ev, kNXEventDataVersion, flags | NX_NONCOALSESCEDMASK, options);
    if(res != kIOReturnSuccess && !silence_errors)
        ckb_warn("Post event failed: %x\n", res);

    if(uid != 0)
        seteuid(0);
    if(gid != 0)
        setegid(0);
    euid_guard_stop;
}
Beispiel #19
0
// Quartz event tap support for the secondary display. This makes sure that we
// will show the cursor if a local event comes in while synergy has the cursor
// off the screen.
CGEventRef
COSXScreen::handleCGInputEventSecondary(
	CGEventTapProxy proxy,
	CGEventType type,
	CGEventRef event,
	void* refcon)
{
	// this fix is really screwing with the correct show/hide behavior. it
	// should be tested better before reintroducing.
	return event;

	COSXScreen* screen = (COSXScreen*)refcon;
	if (screen->m_cursorHidden && type == kCGEventMouseMoved) {

		CGPoint pos = CGEventGetLocation(event);
		if (pos.x != screen->m_xCenter || pos.y != screen->m_yCenter) {

			LOG((CLOG_DEBUG "show cursor on secondary, type=%d pos=%d,%d",
					type, pos.x, pos.y));
			screen->showCursor();
		}
	}
	return event;
}
CGPoint MouseMac::getCursorPositionCGPoint()
{
    CGEventRef event = CGEventCreate(NULL);
    return CGEventGetLocation(event);
}
Beispiel #21
0
block_t *screen_Capture(demux_t *p_demux)
{
    demux_sys_t *p_sys = p_demux->p_sys;
    screen_data_t *p_data = (screen_data_t *)p_sys->p_data;
    block_t *p_block;
    CGRect capture_rect;
    CGImageRef image;

    /* forward cursor location */
    CGPoint cursor_pos;

    CGEventRef event = CGEventCreate(NULL);
    cursor_pos = CGEventGetLocation(event);
    CFRelease(event);

    cursor_pos.x -= p_data->screen_left;
    cursor_pos.y -= p_data->screen_top;

    if (p_sys->b_follow_mouse)
        FollowMouse(p_sys, cursor_pos.x, cursor_pos.y);

    capture_rect.origin.x = p_sys->i_left;
    capture_rect.origin.y = p_sys->i_top;
    capture_rect.size.width = p_data->width;
    capture_rect.size.height = p_data->height;

    /* fetch image data */
    image = CGDisplayCreateImageForRect(p_data->display_id, capture_rect);
    if (!image) {
        msg_Warn(p_demux, "no image!");
        return NULL;
    }

    /* create offscreen context */
    if (!p_data->offscreen_context) {
        CGColorSpaceRef colorspace;

        colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);

        p_data->offscreen_bitmap_size = p_sys->fmt.video.i_width * p_sys->fmt.video.i_height * 4;
        p_data->offscreen_bitmap = calloc(1, p_data->offscreen_bitmap_size);
        if (p_data->offscreen_bitmap == NULL) {
            msg_Warn(p_demux, "can't allocate offscreen bitmap");
            CFRelease(image);
            return NULL;
        }

        p_data->offscreen_context = CGBitmapContextCreate(p_data->offscreen_bitmap, p_sys->fmt.video.i_width, p_sys->fmt.video.i_height, 8, p_sys->fmt.video.i_width * 4, colorspace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little);
        if (!p_data->offscreen_context) {
            msg_Warn(p_demux, "can't create offscreen bitmap context");
            CFRelease(image);
            return NULL;
        }

        CGColorSpaceRelease(colorspace);

        p_data->offscreen_rect = CGRectMake(0, 0, p_sys->fmt.video.i_width, p_sys->fmt.video.i_height);
    }

    /* fetch cursor image */
    CGImageRef cursor_image;
    int cid = CGSMainConnectionID();
    CGPoint outHotSpot;
    cursor_image = CGSCreateRegisteredCursorImage(cid, (char *)"com.apple.coregraphics.GlobalCurrent", &outHotSpot);

    /* draw screen image and cursor image */
    CGRect cursor_rect;
    cursor_rect.size.width = CGImageGetWidth(cursor_image);
    cursor_rect.size.height = CGImageGetHeight(cursor_image);
    cursor_rect.origin.x = cursor_pos.x - p_sys->i_left - outHotSpot.x;
    cursor_rect.origin.y = p_data->offscreen_rect.size.height
                           - (cursor_pos.y + cursor_rect.size.height - p_sys->i_top - outHotSpot.y);

    CGContextDrawImage(p_data->offscreen_context, p_data->offscreen_rect, image);
    CGContextDrawImage(p_data->offscreen_context, cursor_rect, cursor_image);

    /* build block */
    p_block = block_Alloc(p_data->offscreen_bitmap_size);
    if (!p_block) {
        msg_Warn(p_demux, "can't get block");
        CFRelease(image);
        return NULL;
    }

    memmove(p_block->p_buffer, p_data->offscreen_bitmap, p_data->offscreen_bitmap_size);

    CFRelease(image);

    return p_block;
}
Beispiel #22
0
CGPoint MousePos () {
	CGEventRef ourEvent = CGEventCreate(NULL);
	return CGEventGetLocation(ourEvent); 
}
// 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;
}
Beispiel #24
0
// Quartz event tap support
CGEventRef
COSXScreen::handleCGInputEvent(CGEventTapProxy proxy,
							   CGEventType type,
							   CGEventRef event,
							   void* refcon)
{
	COSXScreen* screen = (COSXScreen*)refcon;
	CGPoint pos;

	switch(type) {
		case kCGEventLeftMouseDown:
		case kCGEventRightMouseDown:
		case kCGEventOtherMouseDown:
			screen->onMouseButton(true, CGEventGetIntegerValueField(event, kCGMouseEventButtonNumber) + 1);
			break;
		case kCGEventLeftMouseUp:
		case kCGEventRightMouseUp:
		case kCGEventOtherMouseUp:
			screen->onMouseButton(false, CGEventGetIntegerValueField(event, kCGMouseEventButtonNumber) + 1);
			break;
		case kCGEventMouseMoved:
		case kCGEventLeftMouseDragged:
		case kCGEventRightMouseDragged:
		case kCGEventOtherMouseDragged:
			pos = CGEventGetLocation(event);
			screen->onMouseMove(pos.x, pos.y);
			
			// The system ignores our cursor-centering calls if
			// we don't return the event. This should be harmless,
			// but might register as slight movement to other apps
			// on the system. It hasn't been a problem before, though.
			return event;
			break;
		case kCGEventScrollWheel:
			screen->onMouseWheel(screen->mapScrollWheelToSynergy(
								 CGEventGetIntegerValueField(event, kCGScrollWheelEventDeltaAxis2)),
								 screen->mapScrollWheelToSynergy(
								 CGEventGetIntegerValueField(event, kCGScrollWheelEventDeltaAxis1)));
			break;
		case kCGEventKeyDown:
		case kCGEventKeyUp:
		case kCGEventFlagsChanged:
			screen->onKey(event);
			break;
		case kCGEventTapDisabledByTimeout:
			// Re-enable our event-tap
			CGEventTapEnable(screen->m_eventTapPort, true);
			LOG((CLOG_NOTE "quartz event tap was disabled by timeout, re-enabling"));
			break;
		case kCGEventTapDisabledByUserInput:
			LOG((CLOG_ERR "quartz event tap was disabled by user input"));
			break;
		case NX_NULLEVENT:
			break;
		case NX_SYSDEFINED:
			// Unknown, forward it
			return event;
			break;
		case NX_NUMPROCS:
			break;
		default:
			LOG((CLOG_NOTE "unknown quartz event type: 0x%02x", type));
	}
	
	if(screen->m_isOnScreen) {
		return event;
	} else {
		return NULL;
	}
}
Beispiel #25
0
CGPoint mousePos() {
    CGEventRef event = CGEventCreate(nil);
    CGPoint loc = CGEventGetLocation(event);
    CFRelease(event);
    return loc;
}
Beispiel #26
0
internal CGEventRef
CGEventCallback(CGEventTapProxy Proxy, CGEventType Type, CGEventRef Event, void *Refcon)
{
    switch(Type)
    {
        case kCGEventTapDisabledByTimeout:
        case kCGEventTapDisabledByUserInput:
        {
            DEBUG("Notice: Restarting Event Tap");
            CGEventTapEnable(KWMMach.EventTap, true);
        } break;
        case kCGEventMouseMoved:
        {
            if(KWMSettings.Focus == FocusModeAutoraise)
                AXLibConstructEvent(AXEvent_MouseMoved, NULL, false);
        } break;
        case kCGEventLeftMouseDown:
        {
            if(HasFlags(&KWMSettings, Settings_MouseDrag))
            {
                if(MouseDragKeyMatchesCGEvent(Event))
                {
                    AXLibConstructEvent(AXEvent_LeftMouseDown, NULL, false);
                    return NULL;
                }
            }
        } break;
        case kCGEventLeftMouseUp:
        {
            if(HasFlags(&KWMSettings, Settings_MouseDrag))
                AXLibConstructEvent(AXEvent_LeftMouseUp, NULL, false);
        } break;
        case kCGEventLeftMouseDragged:
        {
            if(HasFlags(&KWMSettings, Settings_MouseDrag))
            {
                CGPoint *Cursor = (CGPoint *) malloc(sizeof(CGPoint));
                *Cursor = CGEventGetLocation(Event);
                AXLibConstructEvent(AXEvent_LeftMouseDragged, Cursor, false);
            }
        } break;
        case kCGEventRightMouseDown:
        {
            if(HasFlags(&KWMSettings, Settings_MouseDrag))
            {
                if(MouseDragKeyMatchesCGEvent(Event))
                {
                    AXLibConstructEvent(AXEvent_RightMouseDown, NULL, false);
                    return NULL;
                }
            }
        } break;
        case kCGEventRightMouseUp:
        {
            if(HasFlags(&KWMSettings, Settings_MouseDrag))
                AXLibConstructEvent(AXEvent_RightMouseUp, NULL, false);
        } break;
        case kCGEventRightMouseDragged:
        {
            if(HasFlags(&KWMSettings, Settings_MouseDrag))
            {
                CGPoint *Cursor = (CGPoint *) malloc(sizeof(CGPoint));
                *Cursor = CGEventGetLocation(Event);
                AXLibConstructEvent(AXEvent_RightMouseDragged, Cursor, false);
            }
        } break;

        default: {} break;
    }

    return Event;
}