Skip to content

Commit

Permalink
Update pimoroni_trackball.py (#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
regicidalplutophage authored Aug 18, 2024
1 parent b9bd8b5 commit 5bcec78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 5 additions & 5 deletions docs/en/pimoroni_trackball.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ trackball = Trackball(
# optional: set rotation angle of the trackball breakout board, default is 1
angle_offset=1.6,
handlers=[
# act like an encoder, input arrow keys
# act like an encoder, input arrow keys, enter when pressed
KeyHandler(KC.UP, KC.RIGHT, KC.DOWN, KC.LEFT, KC.ENTER),
# on layer 1 and above use the default pointing behavior
PointingHandler(),
# use ScrollDirection.NATURAL (default) or REVERSE to change the scrolling direction
ScrollHandler(scroll_direction=ScrollDirection.NATURAL)
# on layer 1 and above use the default pointing behavior, left click when pressed
PointingHandler(on_press=KC.MB_LMB),
# use ScrollDirection.NATURAL (default) or REVERSE to change the scrolling direction, left click when pressed
ScrollHandler(scroll_direction=ScrollDirection.NATURAL, on_press=KC.MB_LMB)
]
)

Expand Down
10 changes: 7 additions & 3 deletions kmk/modules/pimoroni_trackball.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,23 @@ def handle(self, keyboard, trackball, x, y, switch, state):


class PointingHandler(TrackballHandler):
def __init__(self, on_press=KC.MB_LMB):
self.on_press = on_press

def handle(self, keyboard, trackball, x, y, switch, state):
if x:
AX.X.move(keyboard, x)
if y:
AX.Y.move(keyboard, y)

if switch == 1: # Button changed state
keyboard.pre_process_key(KC.MB_LMB, is_pressed=state)
keyboard.pre_process_key(self.on_press, is_pressed=state)


class ScrollHandler(TrackballHandler):
def __init__(self, scroll_direction=ScrollDirection.NATURAL):
def __init__(self, scroll_direction=ScrollDirection.NATURAL, on_press=KC.MB_LMB):
self.scroll_direction = scroll_direction
self.on_press = on_press

def handle(self, keyboard, trackball, x, y, switch, state):
if self.scroll_direction == ScrollDirection.REVERSE:
Expand All @@ -98,7 +102,7 @@ def handle(self, keyboard, trackball, x, y, switch, state):
AX.W.move(keyboard, y)

if switch == 1: # Button changed state
keyboard.pre_process_key(KC.MB_LMB, is_pressed=state)
keyboard.pre_process_key(self.on_press, is_pressed=state)


class KeyHandler(TrackballHandler):
Expand Down

0 comments on commit 5bcec78

Please sign in to comment.