Skip to content

Instantly share code, notes, and snippets.

@tararoys
Created April 19, 2021 17:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tararoys/cdabc3bab686abd8d9b585afd7c481da to your computer and use it in GitHub Desktop.
Save tararoys/cdabc3bab686abd8d9b585afd7c481da to your computer and use it in GitHub Desktop.
hiss_spiral_mouse.py

This mouse has a couple of features

  1. you only need to be able to hiss to turn it on operate it. No need for spoken words, or vocal cords, or anything but the ability to start making a hissing noise and stop making a hissing noise.

(it does require being able to make the popping noise to make the crosshairs disappear)

This mouse works the same way a fed-ex delivery truck works: It moves every time you start hissing, then makes a 90 degree clockwise turn every time you stop. It follows a pattern: north, east, south, west. So you can aim the mouse in a direction, and if you overshoot, you can go 'around the block' to get to where you are going.

This mouse will allow you to get anywhere on the screen with a series of hisses.

see how it works here

from talon import Module, Context, canvas, ctrl, cron, ui, actions, app, imgui
from talon.types import Point2d
import time
mod = Module()
crosshairs_moving = False
crosshairs_tick_job = None
crosshairs_position = Point2d(ctrl.mouse_pos()[0], ctrl.mouse_pos()[1])
direction = 'east'
hissing = ""
crosshairs_canvas = None
ctx = Context()
ctx.matches = r"""
mode: command
"""
def crosshairs_tick_cb():
global direction
if crosshairs_moving:
if direction == "north":
ctrl.mouse_move(ctrl.mouse_pos()[0], ctrl.mouse_pos()[1] - 10)
elif direction == "east":
ctrl.mouse_move(ctrl.mouse_pos()[0] + 10, ctrl.mouse_pos()[1])
elif direction == "south":
ctrl.mouse_move(ctrl.mouse_pos()[0], ctrl.mouse_pos()[1] + 10)
elif direction == "west":
ctrl.mouse_move(ctrl.mouse_pos()[0] - 10, ctrl.mouse_pos()[1])
def crosshairs_canvas_draw(canvas):
print(str(canvas))
print(ctrl.mouse_pos())
paint= canvas.paint
paint.color = "00ff00ff"
paint.stroke_width = 6
canvas.draw_points(canvas.PointMode.LINES,
[Point2d(ctrl.mouse_pos()[0], 0),
Point2d(ctrl.mouse_pos()[0], ui.screens()[0].rect.height - 1)])
canvas.draw_points(canvas.PointMode.LINES,
[Point2d(0, ctrl.mouse_pos()[1]),
Point2d(ui.screens()[0].rect.width - 1, ctrl.mouse_pos()[1])])
@imgui.open(y=600)
def gui(gui: imgui.GUI):
global history
gui.text(direction)
gui.line()
gui.text(hissing)
@mod.action_class
class HissSpiralActions:
def spiral_start():
"""Starts the "spiral" mouse"""
global crosshairs_canvas
global crosshairs_position
global crosshairs_tick_job
if crosshairs_tick_job:
cron.cancel(crosshairs_tick_job)
crosshairs_tick_job = cron.interval("40ms", crosshairs_tick_cb)
if crosshairs_canvas is None:
crosshairs_canvas = canvas.Canvas(0, 0, ui.screens()[0].rect.width -1 , ui.screens()[0].rect.height -1)
crosshairs_position = Point2d(ctrl.mouse_pos()[0], ctrl.mouse_pos()[1])
crosshairs_canvas.register("draw", crosshairs_canvas_draw)
def spiral_stop():
"""Stops the "spiral" mouse"""
global crosshairs_canvas
cron.cancel(crosshairs_tick_job)
crosshairs_canvas.unregister("draw", crosshairs_canvas_draw)
crosshairs_canvas.hide()
crosshairs_canvas = None
def crosshairs_move():
"""move the crosshairs in a 'fed-ex truck circling the block' clockwise fashioin"""
global crosshairs_position
global direction
global crosshairs_moving
global hissing
crosshairs_moving = True
hissing = "hissing"
def crosshairs_stop():
"""stop the crosshairs"""
global direction
global crosshairs_moving
global hissing
crosshairs_moving = False
if direction == "north":
direction = "east"
elif direction == "east":
direction = "south"
elif direction == "south":
direction = "west"
elif direction == "west":
direction = "north"
hissing = ""
def crosshairs_history_show():
"displaying how long you've been hissing"
gui.show()
def crosshairs_history_hide():
"hiding the history"
gui.hide()
-
start driving: user.spiral_start()
stop driving: user.spiral_stop()
action(user.noise_hiss_start): user.crosshairs_move()
action(user.noise_hiss_stop): user.crosshairs_stop()
action(user.noise_pop): user.racer_gas_toggle()
from talon import Module, actions, noise
noise_module = Module()
@noise_module.action_class
class NoiseActions:
def noise_pop():
"""Invoked when the user does the pop noise."""
pass
def noise_hiss_start():
"""Invoked when the user starts hissing (potentially while speaking)"""
pass
def noise_hiss_stop():
"""Invoked when the user finishes hissing (potentially while speaking)"""
pass
def pop_handler(blah):
actions.user.noise_pop()
def hiss_handler(active):
if active:
actions.user.noise_hiss_start()
else:
actions.user.noise_hiss_stop()
noise.register("pop", pop_handler)
noise.register("hiss", hiss_handler)
-
start driving: user.spiral_start()
stop driving: user.spiral_stop()
action(user.noise_hiss_start): user.crosshairs_move()
action(user.noise_hiss_stop): user.crosshairs_stop()
action(user.noise_pop): user.racer_gas_toggle()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment