input¶
Enums holding values representing mouse button and keyboard key events.
Mouse¶
In order to define custom mouse events for a widget,
one can override the tanmatsu.widgets.Widget.event_event() method:
import tanmatsu.input as ti
import tanmatsu.geometry as tg
class ExampleWidgetXYZ(ExampleWidgetABC):
def mouse_event(
self,
button: ti.Mouse_button,
modifier: ti.Mouse_modifier,
state: ti.Mouse_state,
position: tg.Point
) -> bool:
# Call super() to check if any parent classes
# want to consume the event.
if super().mouse_event(button, modifier, state, position):
return True
if self.scrollable() is False:
return False
match button, modifier:
# Mouse wheel
case ti.Mouse_button.SCROLL_UP, ti.Mouse_modifier.NONE:
self.scroll(delta_y=-1)
case ti.Mouse_button.SCROLL_DOWN, ti.Mouse_modifier.NONE:
self.scroll(delta_y=+1)
# Mouse wheel + shift
case ti.Mouse_button.SCROLL_UP, ti.Mouse_modifier.SHIFT:
self.scroll(delta_x=-1)
case ti.Mouse_button.SCROLL_DOWN, ti.Mouse_modifier.SHIFT:
self.scroll(delta_x=+1)
# return False if the button isn't one we're
# interested in
case _:
return False
# return True if we didn't hit the fallthrough case,
# meaning we did find a button we were interested in.
return True
Mouse State¶
Keyboard¶
In order to define custom key events for a widget,
one can override the tanmatsu.widgets.Widget.keyboard_event() method:
import tanmatsu.input as ti
class ExampleWidgetXYZ(ExampleWidgetABC):
def keyboard_event(
self,
key: ti.Keyboard_key | str,
modifier: ti.Keyboard_modifier
) -> bool:
# Call super() to check if any parent classes
# want to consume the event.
if super().keyboard_event(key, modifier):
return True
match key:
case ti.Keyboard_key.ENTER:
self.enter_key()
case 'a':
self.latin_a_key()
case 'あ':
self.hiragana_a_key()
case c if not isinstance(c, ti.Keyboard_key):
self.any_character(c)
case _:
# return False if the key isn't one we're
# interested in
return False
# return True if we didn't hit the fallthrough case,
# meaning we did find a key we were interested in.
return True
Keyboard Keys¶
- class tanmatsu.input.Keyboard_key(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
The keyboard key.
- TAB = 1¶
- ENTER = 2¶
- BACKSPACE = 3¶
- ESCAPE = 4¶
- F1 = 5¶
- F2 = 6¶
- F3 = 7¶
- F4 = 8¶
- F5 = 9¶
- F6 = 10¶
- F7 = 11¶
- F8 = 12¶
- F9 = 13¶
- F10 = 14¶
- F11 = 15¶
- F12 = 16¶
- INSERT = 17¶
- DELETE = 18¶
- HOME = 19¶
- END = 20¶
- PAGE_UP = 21¶
- PAGE_DOWN = 22¶
- UP_ARROW = 23¶
- DOWN_ARROW = 24¶
- LEFT_ARROW = 25¶
- RIGHT_ARROW = 26¶