Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Shackless committed Apr 10, 2024
2 parents ab8c337 + f356a56 commit 195e0eb
Show file tree
Hide file tree
Showing 18 changed files with 1,145 additions and 881 deletions.
1 change: 1 addition & 0 deletions api/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class SummarizeProvider(Enum):
class KeyboardRecordingType(Enum):
SINGLE = "single"
MACRO = "macro"
MACRO_ADVANCED = "macro_advanced"


class WingmanProRegion(Enum):
Expand Down
8 changes: 8 additions & 0 deletions api/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,17 @@ class CommandKeyboardConfig(BaseModel):
hotkey_codes: Optional[list[int]] = None
"""The hotkey codes. Can be a single key like 65 or a combination like 162+160+65. Optional."""

hotkey_extended: Optional[bool] = None
"""Whether the hotkey is an extended key. Optional."""

hold: Optional[float] = None
"""The duration the key will be pressed in seconds. Optional."""

press: Optional[bool] = None
"""Whether to press the key. Optional."""

release: Optional[bool] = None
"""Whether to release the key. Optional."""

class CommandMouseConfig(BaseModel):
button: Optional[str] = None
Expand Down
6 changes: 6 additions & 0 deletions keyboard/keyboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@ def send(hotkey, do_press=True, do_release=True):

_listener.is_replaying = False

def direct_event(scancode, event_type):
"""
Sends a key event directly to the OS, without any processing.
"""
_os_keyboard.direct_event(scancode, event_type)

# Alias.
press_and_release = send

Expand Down
7 changes: 7 additions & 0 deletions keyboard/keyboard/_darwinkeyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,13 @@ def handler(self, proxy, e_type, event, refcon):
def init():
key_controller = KeyController()

def direct_event(scan_code, event_type):
""" Sends a key event directly, without any processing """
if event_type == 0 or event_type == 1:
key_controller.press(scan_code)
elif event_type == 2 or event_type == 3:
key_controller.release(scan_code)

def press(scan_code):
""" Sends a 'down' event for the specified scan code """
key_controller.press(scan_code)
Expand Down
6 changes: 4 additions & 2 deletions keyboard/keyboard/_keyboard_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ class KeyboardEvent(object):
device = None
modifiers = None
is_keypad = None
is_extended = None

def __init__(self, event_type, scan_code, name=None, time=None, device=None, modifiers=None, is_keypad=None):
def __init__(self, event_type, scan_code, name=None, time=None, device=None, modifiers=None, is_keypad=None, is_extended=None):
self.event_type = event_type
self.scan_code = scan_code
self.time = now() if time is None else time
self.device = device
self.is_keypad = is_keypad
self.modifiers = modifiers
self.is_extended = is_extended
if name:
self.name = normalize_name(name)

def to_json(self, ensure_ascii=False):
attrs = dict(
(attr, getattr(self, attr)) for attr in ['event_type', 'scan_code', 'name', 'time', 'device', 'is_keypad', 'modifiers']
(attr, getattr(self, attr)) for attr in ['event_type', 'scan_code', 'name', 'time', 'device', 'is_keypad', 'modifiers', 'is_extended']
if not attr.startswith('_')
)
return json.dumps(attrs, ensure_ascii=ensure_ascii)
Expand Down
3 changes: 3 additions & 0 deletions keyboard/keyboard/_nixkeyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def listen(callback):
is_keypad = scan_code in keypad_scan_codes
callback(KeyboardEvent(event_type=event_type, scan_code=scan_code, name=name, time=time, device=device_id, is_keypad=is_keypad, modifiers=pressed_modifiers_tuple))

def direct_event(scan_code, event_type):
write_event(scan_code, event_type == 0 or event_type == 1)

def write_event(scan_code, is_down):
build_device()
device.write_event(EV_KEY, scan_code, int(is_down))
Expand Down
Loading

0 comments on commit 195e0eb

Please sign in to comment.