def _toggle(_): global hideJob ctrl.cursor_visible(show) if show: cron.cancel(hideJob) else: hideJob = cron.interval("500ms", lambda: ctrl.cursor_visible(show))
def reset(self, _): self.offset_x = self.main_screen.width // 2 self.offset_y = self.main_screen.height // 2 self.angle = 0 self.speed = 0.0 self.main_screen = ui.main_screen() ctrl.cursor_visible(True)
def show_cursor_helper(show): """Show/hide the cursor""" if app.platform == "windows": import ctypes import winreg import win32con try: Registrykey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Control Panel\Cursors", 0, winreg.KEY_WRITE) for value_name, value in default_cursor.items(): if show: winreg.SetValueEx(Registrykey, value_name, 0, winreg.REG_EXPAND_SZ, value) else: winreg.SetValueEx(Registrykey, value_name, 0, winreg.REG_EXPAND_SZ, hidden_cursor) winreg.CloseKey(Registrykey) ctypes.windll.user32.SystemParametersInfoA(win32con.SPI_SETCURSORS, 0, None, 0) except WindowsError: print("Unable to show_cursor({})".format(str(show))) else: ctrl.cursor_visible(show)
def mouse_sleep(): """Disables control mouse, zoom mouse, and re-enables cursor""" global dragging eye_zoom_mouse.zoom_mouse.disable() eye_mouse.control_mouse.disable() ctrl.cursor_visible(True) stop_scrolling() if dragging: mouse_drag()
def on_pop(self, noise): if len(mouse.eye_hist) < 2: return if noise != 'hiss_start': return now = time.time() if self.state == STATE_IDLE: if now - self.last_click < config.double_click: ctrl.mouse_click(hold=32000) return l, r = mouse.eye_hist[-1] p = (l.gaze + r.gaze) / 2 main_gaze = -0.02 < p.x < 1.02 and -0.02 < p.y < 1.02 and bool( l or r) if not main_gaze: pass # return ctrl.cursor_visible(False) self.gaze = eye_config.size_px * p capture = self.gaze - (config.screen_area / 2) capture.x = min(max(capture.x, 0), main_screen.width - config.screen_area.x) capture.y = min(max(capture.y, 0), main_screen.height - config.screen_area.y) self.rect = (capture.x, capture.y, config.screen_area.x, config.screen_area.y) self.pos = self.gaze - (config.screen_area * config.img_scale) / 2 self.pos.x = min( max(self.pos.x, 0), main_screen.width - config.screen_area.x * config.img_scale) self.pos.y = min( max(self.pos.y, 0), main_screen.height - config.screen_area.y * config.img_scale) self.size = Point2d(config.screen_area.x * config.img_scale, config.screen_area.y * config.img_scale) self.off = Point2d(0, 0) self.frame = 0 self.canvas = canvas.Canvas(self.pos.x, self.pos.y, self.size.x, self.size.y) if not config.live: self.capture() self.canvas.register('draw', self.draw) self.state = STATE_OVERLAY elif self.state == STATE_OVERLAY: self.state = STATE_IDLE ctrl.cursor_visible(True) self.canvas.unregister('draw', self.draw) self.canvas.close() self.canvas = None dot, origin = self.get_pos() if origin: ctrl.mouse(origin.x, origin.y) ctrl.mouse_click(hold=32000) self.last_click = time.time()
def cursor(self, show): now = time.time() if show: self.last_show = now elif self.show and now - self.last_show < 0.5: return if show != self.show: ctrl.cursor_visible(show) self.show = show
def restore(self): # l, r = mouse.eye_hist[-1] # print(f"{(l.pos.z + r.pos.z) / 2}") ctrl.cursor_visible(True) if self.top is not None: # print(f"Restore left: {pos} {self.saved_mouse_left}") if self.saved_mouse_top: mouse.last_ctrl = self.saved_mouse_top ctrl.mouse(self.saved_mouse_top.x, self.saved_mouse_top.y) # self.saved_mouse_left = None self.main_gaze = False
def insert(s): global last_insert, reenable_job last_insert = s if eye_zoom_mouse.zoom_mouse.enabled: eye_zoom_mouse.zoom_mouse.toggle() if eye_mouse.control_mouse.enabled: eye_mouse.control_mouse.toggle() ctrl.cursor_visible(True) if reenable_job is None: reenable_job = cron.after("3s", enable_tracking) if reenable_job is not None: debounce_enable_job() Str(s)(None)
def restore(self): # l, r = mouse.eye_hist[-1] # print(f"{(l.pos.z + r.pos.z) / 2}") ctrl.cursor_visible(True) pos = mouse.xy_hist[-1] if self.right is None or (pos.x < main.width / 2 and self.left is not None): # print(f"Restore left: {pos} {self.saved_mouse_left}") if self.saved_mouse_left: mouse.last_ctrl = self.saved_mouse_left ctrl.mouse(self.saved_mouse_left.x, self.saved_mouse_left.y) # self.saved_mouse_left = None self.main_gaze = False elif pos.x > main.width / 2: # print(f"Restore right: {pos} {self.saved_mouse_right}") if self.saved_mouse_right: mouse.last_ctrl = self.saved_mouse_right ctrl.mouse(self.saved_mouse_right.x, self.saved_mouse_right.y) # self.saved_mouse_right = None self.main_gaze = False
def on_gaze(self, b): p = Point2d(*ctrl.mouse_pos()) on_main = is_on_main(p) if not control_mouse.enabled or not on_main or (mouse.last_ctrl and mouse.break_force > 6): self.cursor(True) ctrl.cursor_visible(True) else: try: # hides after every eye jump until a head movement origin = mouse.origin frames = [xy for xy in mouse.xy_hist if xy.ts >= origin.ts] m = max([(origin - xy).len() for xy in frames]) self.cursor(m > 5) return # this variant hides the cursor on every eye jump until it settles (can tweak radius up to 200) p, origin, radius = mouse.zone1 self.cursor(radius > 20) except Exception: self.cursor(True)
def start(self, *_): if self.active: return self.mcanvas.register('draw', self.draw) self.active = True ctrl.cursor_visible(False)
def eye_mouse_wake(): """Enable control mouse, zoom mouse, and disables cursor""" eye_zoom_mouse.zoom_mouse.enable() eye_mouse.control_mouse.enable() ctrl.cursor_visible(False)
def on_focus(self, win): ctrl.cursor_visible(self.show)
def toggle_mouse_visibility(m): if str(m._words[1]) == 'show': ctrl.cursor_visible(True) return ctrl.cursor_visible(False)
def on_focus(self, win): ctrl.cursor_visible(self.show or not control_mouse.enabled)
def mouse_hide_cursor(): """Hides the cursor""" ctrl.cursor_visible(False)
def _toggle(_): global showCursor showCursor = show ctrl.cursor_visible(show)
def show_cursor_helper(show): """Show/hide the cursor""" ctrl.cursor_visible(show)
def reset(self, _): self.offset_x = self.center_x self.offset_y = self.center_y self.first_hiss = True ctrl.cursor_visible(True)
def stopScrolling(m): global scrollAmount, scrollJob scrollAmount = 0 cron.cancel(scrollJob) def toggle_cursor(show): def _toggle(_): global showCursor showCursor = show ctrl.cursor_visible(show) return _toggle scrollAmount = 0 scrollJob = None showCursor = True keymap = { "hide cursor": toggle_cursor(False), "show cursor": toggle_cursor(True), "wheel down continuous": startScrolling(10), "wheel up continuous": startScrolling(-10), "wheel stop": stopScrolling, } ctx.keymap(keymap) ctrl.cursor_visible(True)
def stop(self, *_): self.mcanvas.unregister('draw', self.draw) self.active = False ctrl.cursor_visible(True)
def _toggle(_): ctrl.cursor_visible(show)
def mouse_show_cursor(): """Shows the cursor""" ctrl.cursor_visible(True)