def _nativeEventCallback(self,event): try: if self.isReportingEvents(): logged_time=currentSec() event_array=event[0] event_array[3]=Computer._getNextEventID() display_index=self._display_device.getIndex() x,y=self._display_device.pixel2DisplayCoord(event_array[15],event_array[16],display_index) event_array[15]=x event_array[16]=y self._lastPosition=self._position self._position=x,y self._last_display_index=self._display_index self._display_index=display_index self._addNativeEventToBuffer(event_array) self._last_callback_time=logged_time except: ioHub.printExceptionDetailsToStdErr() # Must return original event or no mouse events will get to OSX! return 1
def _getIOHubEventObject(self,native_event_data): logged_time, event=native_event_data p = event.Position px=p[0] py=p[1] bstate,etype,bnum=self._mouse_event_mapper[event.Message] if event.Message == self.WM_MOUSEMOVE and event.ActiveButtons>0: etype=EventConstants.MOUSE_DRAG confidence_interval=0.0 delay=0.0 # From MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644939(v=vs.85).aspx # The time is a long integer that specifies the elapsed time, in milliseconds, from the time the system was started to the time the message was # created (that is, placed in the thread's message queue).REMARKS: The return value from the GetMessageTime function does not necessarily increase # between subsequent messages, because the value wraps to zero if the timer count exceeds the maximum value for a long integer. To calculate time # delays between messages, verify that the time of the second message is greater than the time of the first message; then, subtract the time of the # first message from the time of the second message. device_time = event.Time/1000.0 # convert to sec hubTime = logged_time r= [0, 0, 0, #device id Computer._getNextEventID(), etype, device_time, logged_time, hubTime, confidence_interval, delay, 0, event.DisplayIndex, bstate, bnum, event.ActiveButtons, px, py, 0, #scroll_dx not supported 0, #scroll_x not supported event.Wheel, event.WheelAbsolute, event.Window] return r
def _nativeEventCallback(self, *args): try: proxy, etype, event, refcon = args if self.isReportingEvents(): logged_time = currentSec() if etype == kCGEventTapDisabledByTimeout: ioHub.print2err("** WARNING: Mouse Tap Disabled due to timeout. Re-enabling....: ", etype) CGEventTapEnable(self._tap, True) return event else: confidence_interval = 0.0 delay = 0.0 iohub_time = logged_time device_time = CGEventGetTimestamp(event) * self.DEVICE_TIME_TO_SECONDS ioe_type = EventConstants.UNDEFINED px, py = CGEventGetLocation(event) multi_click_count = CGEventGetIntegerValueField(event, kCGMouseEventClickState) mouse_event = NSEvent.eventWithCGEvent_(event) window_handle = mouse_event.windowNumber() # TO DO: Implement multimonitor location based on mouse location support. # Currently always uses monitor index 0 display_index = self.getDisplayIndexForMousePosition((px, py)) if display_index == -1: if self._last_display_index is not None: display_index = self._last_display_index else: ioHub.print2err( "!!! _nativeEventCallback error: mouse event pos {0} not in any display bounds!!!".format( event.Position ) ) ioHub.print2err("!!! -> SKIPPING EVENT") ioHub.print2err("===============") return event result = self._validateMousePosition((px, py), display_index) if result != True: ioHub.print2err( "!!! _validateMousePosition made ajustment: {0} to {1}".format((px, py), result) ) nx, ny = result display_index = self.getDisplayIndexForMousePosition((nx, ny)) ioHub.print2err( "Going to Update mousePosition: {0} => {1} on D {2}".format( (px, py), (ny, ny), display_index ) ) px, py = nx, ny self._nativeSetMousePos(px, py) px, py = self._display_device.pixel2DisplayCoord(px, py, display_index) self._lastPosition = self._position self._position = px, py self._last_display_index = self._display_index self._display_index = display_index # TO DO: Supported reporting scroll x info for OSX. # This also suggests not having scoll up and down events and # just having the one scroll event type, regardless of direction / dimension scroll_dx = 0 scroll_dy = 0 button_state = 0 if etype in pressID: button_state = MouseConstants.MOUSE_BUTTON_STATE_PRESSED if multi_click_count > 1: ioe_type = EventConstants.MOUSE_MULTI_CLICK else: ioe_type = EventConstants.MOUSE_BUTTON_PRESS elif etype in releaseID: button_state = MouseConstants.MOUSE_BUTTON_STATE_RELEASED ioe_type = EventConstants.MOUSE_BUTTON_RELEASE elif etype in dragID: ioe_type = EventConstants.MOUSE_DRAG elif etype == kCGEventMouseMoved: ioe_type = EventConstants.MOUSE_MOVE elif etype == kCGEventScrollWheel: ioe_type = EventConstants.MOUSE_SCROLL scroll_dy = CGEventGetIntegerValueField(event, kCGScrollWheelEventPointDeltaAxis1) scroll_dx = CGEventGetIntegerValueField(event, kCGScrollWheelEventPointDeltaAxis2) self._scrollPositionX += scroll_dx self._scrollPositionY += scroll_dy iohub_button_id = self._IOHUB_BUTTON_ID_MAPPINGS.get(etype, 0) if iohub_button_id in self.activeButtons: self.activeButtons[iohub_button_id] = int( button_state == MouseConstants.MOUSE_BUTTON_STATE_PRESSED ) pressed_buttons = 0 for k, v in self.activeButtons.iteritems(): pressed_buttons += k * v # Create Event List # index 0 and 1 are session and exp. ID's # index 2 is (yet to be used) device_id ioe = self._EVENT_TEMPLATE_LIST ioe[3] = Computer._getNextEventID() ioe[4] = ioe_type # event type code ioe[5] = device_time ioe[6] = logged_time ioe[7] = iohub_time ioe[8] = confidence_interval ioe[9] = delay # index 10 is filter id, not used at this time ioe[11] = display_index ioe[12] = button_state ioe[13] = iohub_button_id ioe[14] = pressed_buttons ioe[15] = px ioe[16] = py ioe[17] = int(scroll_dx) ioe[18] = int(self._scrollPositionX) ioe[19] = int(scroll_dy) ioe[20] = int(self._scrollPositionY) ioe[21] = window_handle self._addNativeEventToBuffer(copy(ioe)) self._last_callback_time = logged_time except: ioHub.printExceptionDetailsToStdErr() CGEventTapEnable(self._tap, False) # Must return original event or no mouse events will get to OSX! return event