-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathInputKeyboard.py
More file actions
57 lines (46 loc) · 1.68 KB
/
InputKeyboard.py
File metadata and controls
57 lines (46 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from pxr import Usd, UsdGeom, UsdSkel, UsdShade, Sdf, Gf, Tf
import carb
import carb.input
import omni.kit.app
# Reference:
# https://docs.omniverse.nvidia.com/kit/docs/kit-manual/latest/carb.input.html
# ------------------------------------------.
# Input with Keyboard.
# ------------------------------------------.
class InputKeyboard:
_keyboard = None
_input = None
_keyboard_subs = None
def __init__(self):
pass
# Keyboard event.
def _keyboard_event(self, event : carb.input.KeyboardEvent):
if event.type == carb.input.KeyboardEventType.KEY_PRESS:
print(f"KEY_PRESS : {event.input}")
if event.type == carb.input.KeyboardEventType.KEY_RELEASE:
print(f"KEY_RELEASE : {event.input}")
return True
def startup(self):
# Assign keyboard event.
appwindow = omni.appwindow.get_default_app_window()
self._keyboard = appwindow.get_keyboard()
self._input = carb.input.acquire_input_interface()
try:
self._keyboard_subs = self._input.subscribe_to_keyboard_events(self._keyboard, self._keyboard_event)
except Exception:
self._keyboard_subs = None
def shutdown(self):
# Release keyboard event.
if self._input is not None and self._keyboard_subs is not None:
try:
self._input.unsubscribe_to_keyboard_events(self._keyboard, self._keyboard_subs)
except Exception:
pass
self._keyboard_subs = None
self._keyboard = None
self._input = None
# -----------------------------------------.
keyboardV = InputKeyboard()
keyboardV.startup()
# stop.
#keyboardV.shutdown()