def _handle(self, code, msg, lpdata): if code != SystemHook.HC_ACTION: return data = ctypes.cast(lpdata, self._LPMSLLHOOKSTRUCT).contents # Suppress further propagation of the event if it is filtered if self._event_filter(msg, data) is False: return if msg == self.WM_MOUSEMOVE: self.on_move(data.pt.x, data.pt.y) elif msg in self.CLICK_BUTTONS: button, pressed = self.CLICK_BUTTONS[msg] self.on_click(data.pt.x, data.pt.y, button, pressed) elif msg in self.X_BUTTON_STATE: pressed = self.X_BUTTON_STATE[msg] bt = wintypes.SHORT(data.mouseData >> 16).value button = Button.five if bt == MOUSEINPUT.XBUTTON2: button = Button.four self.on_click(data.pt.x, data.pt.y, button, pressed) elif msg in self.SCROLL_BUTTONS: mx, my = self.SCROLL_BUTTONS[msg] dd = wintypes.SHORT( data.mouseData >> 16).value // self._WHEEL_DELTA self.on_scroll(data.pt.x, data.pt.y, dd * mx, dd * my)
def low_level_callback(code, wparam, lparam): if wparam == 512: self.event_handler(MouseEvent( MouseEvents.MOVE, x=lparam.contents.pt.x, y=lparam.contents.pt.y )) elif wparam == 522: self.event_handler(MouseEvent( MouseEvents.SCROLL, direction="UP" if (wintypes.SHORT(lparam.contents.mouseData >> 16).value // 120) == 1 else "DOWN", velocity=1, x=lparam.contents.pt.x, y=lparam.contents.pt.y )) elif wparam in [513, 514, 516, 517, 519, 520]: self.event_handler(MouseEvent( MouseEvents.CLICK, button=mouse_button_mapping[wparam], direction="DOWN" if wparam in [513, 516, 519] else "UP", x=lparam.contents.pt.x, y=lparam.contents.pt.y )) return CallNextHookEx(None, code, wparam, lparam)
def block_maus_callback(msg, data): global l, deadmau5 global ws if deadmau5: x_pos = data.pt.x y_pos = data.pt.y if msg in CLICK_BUTTONS: button, pressed = CLICK_BUTTONS[msg] monosodium_glutamate = "c%d:%d:%d,%d" % (button, int(pressed), x_pos, y_pos) send_non_blocking(ws, monosodium_glutamate) l.suppress_event() elif msg in SCROLL_BUTTONS: dd = wintypes.SHORT(data.mouseData >> 16).value // _WHEEL_DELTA mx, my = SCROLL_BUTTONS[msg] dx = dd * mx dy = dd * my monosodium_glutamate = "l%d:%d" % (dx, dy) send_non_blocking(ws, monosodium_glutamate) l.suppress_event() elif msg == WM_MOUSEMOVE: monosodium_glutamate = "m%d,%d" % (x_pos, y_pos) send_non_blocking(ws, monosodium_glutamate) # master is dead; 1 < 2 return True
def addBuffer(self, imageFirst, imageLast, buffer_number, xres, yres, bpp): dwImageFirst = wintypes.DWORD(imageFirst) dwImageLast = wintypes.DWORD(imageLast) sBuf = wintypes.SHORT(buffer_number) wXRes = wintypes.WORD(xres) wYRes = wintypes.WORD(yres) wBPP = wintypes.WORD(bpp) return self.f_add(self.hcam, dwImageFirst, dwImageLast, sBuf, wXRes, wYRes, wBPP)
def allocateBuffer(self, xres, yres, buffer_number, num_images=1): sBufNum = wintypes.SHORT(buffer_number) dwSize = wintypes.DWORD(2 * xres * yres * num_images) wBuffer = np.zeros((xres * yres * num_images), dtype=np.uint16) hEvent1 = wintypes.HANDLE() hEvent2 = pywintypes.HANDLE() # err = self.f_allocate(self.hcam, byref(sBufNum), dwSize, addressof(c_void_p(wBuffer.ctypes.data)), byref(hEvent1)) return (err, hEvent1, wBuffer)
def getImage(self, segment, imageFirst, imageLast, buffer_number, xres, yres, bpp): wseg = wintypes.WORD(segment) dwFirst = wintypes.DWORD(imageFirst) dwLast = wintypes.DWORD(imageLast) sBuf = wintypes.SHORT(buffer_number) wXRes = wintypes.WORD(xres) wYRes = wintypes.WORD(yres) wBPP = wintypes.WORD(bpp) return self.f_getImage(self.hcam, wseg, dwFirst, dwLast, sBuf, wXRes, wYRes, wBPP)
def get_buffer_status(self, buf_num): self.SC2_Cam.PCO_GetBufferStatus.argtypes = [ wintypes.HANDLE, wintypes.SHORT, C.POINTER(C.c_uint32), C.POINTER(C.c_uint32) ] sBufNr = wintypes.SHORT(buf_num) dwStatusDLL = C.c_uint32() dwStatusDrv = C.c_uint32() error = self.SC2_Cam.PCO_GetBufferStatus(self.camera_handle, sBufNr, dwStatusDLL, dwStatusDrv) ret = {} if error == 0: ret.update({'dll_status': dwStatusDLL.value}) ret.update({'drv_status': dwStatusDrv.value}) return error, ret
def _handle(self, code, msg, lpdata): if code != SystemHook.HC_ACTION: return data = ctypes.cast(lpdata, self._LPMSLLHOOKSTRUCT).contents if msg == self._WM_MOUSEMOVE: self.on_move(data.pt.x, data.pt.y) elif msg in self._CLICK_BUTTONS: button, pressed = self._CLICK_BUTTONS[msg] self.on_click(data.pt.x, data.pt.y, button, pressed) elif msg in self._SCROLL_BUTTONS: mx, my = self._SCROLL_BUTTONS[msg] dd = wintypes.SHORT( data.mouseData >> 16).value // self._WHEEL_DELTA self.on_scroll(data.pt.x, data.pt.y, dd * mx, dd * my)
def freeBuffer(self, buffer_number): return self.f_free(self.hcam, wintypes.SHORT(buffer_number))