Add ScrollDirection class for the Pimoroni Trackball
Signed-off-by: Salvatore La Bua <slabua@gmail.com>
This commit is contained in:
parent
f674ac6b13
commit
5ba865e4c6
@ -25,15 +25,15 @@ If you have used this thing on a mobile device, you will know it excels at curso
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
|
|
||||||
from kmk.modules.pimoroni_trackball import Trackball, TrackballMode, PointingHandler, KeyHandler, ScrollHandler
|
from kmk.modules.pimoroni_trackball import Trackball, TrackballMode, PointingHandler, KeyHandler, ScrollHandler, ScrollDirection
|
||||||
|
|
||||||
trackball = Trackball(i2c, mode=TrackballMode.MOUSE_MODE, handlers=[
|
trackball = Trackball(i2c, mode=TrackballMode.MOUSE_MODE, handlers=[
|
||||||
# act like an encoder, input arrow keys
|
# act like an encoder, input arrow keys
|
||||||
KeyHandler(KC.UP, KC.RIGHT, KC.DOWN, KC.LEFT, KC.ENTER),
|
KeyHandler(KC.UP, KC.RIGHT, KC.DOWN, KC.LEFT, KC.ENTER),
|
||||||
# on layer 1 and above use the default pointing behavior
|
# on layer 1 and above use the default pointing behavior
|
||||||
PointingHandler(),
|
PointingHandler(),
|
||||||
# use scrolling='natural' (default) or 'reverse' to change the scrolling direction
|
# use scrolling=ScrollDirection.NATURAL (default) or REVERSE to change the scrolling direction
|
||||||
ScrollHandler(scrolling='natural')
|
ScrollHandler(scrolling=ScrollDirection.NATURAL)
|
||||||
])
|
])
|
||||||
|
|
||||||
# now you can use these KeyCodes:
|
# now you can use these KeyCodes:
|
||||||
|
@ -64,6 +64,13 @@ class TrackballMode:
|
|||||||
SCROLL_MODE = const(1)
|
SCROLL_MODE = const(1)
|
||||||
|
|
||||||
|
|
||||||
|
class ScrollDirection:
|
||||||
|
'''Behaviour mode of scrolling: natural or reverse scrolling'''
|
||||||
|
|
||||||
|
NATURAL = const(0)
|
||||||
|
REVERSE = const(1)
|
||||||
|
|
||||||
|
|
||||||
class TrackballHandler:
|
class TrackballHandler:
|
||||||
def handle(self, keyboard, trackball, x, y, switch, state):
|
def handle(self, keyboard, trackball, x, y, switch, state):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
@ -96,11 +103,11 @@ class PointingHandler(TrackballHandler):
|
|||||||
|
|
||||||
|
|
||||||
class ScrollHandler(TrackballHandler):
|
class ScrollHandler(TrackballHandler):
|
||||||
def __init__(self, scrolling='natural'):
|
def __init__(self, scrolling=ScrollDirection.NATURAL):
|
||||||
self.scrolling = scrolling
|
self.scrolling = scrolling
|
||||||
|
|
||||||
def handle(self, keyboard, trackball, x, y, switch, state):
|
def handle(self, keyboard, trackball, x, y, switch, state):
|
||||||
if self.scrolling == 'reverse':
|
if self.scrolling == ScrollDirection.REVERSE:
|
||||||
y = -y
|
y = -y
|
||||||
|
|
||||||
pointing_device = trackball.pointing_device
|
pointing_device = trackball.pointing_device
|
||||||
|
Loading…
x
Reference in New Issue
Block a user