Skip to content

Commit

Permalink
hid: bugfix: handle bad return values
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Mar 20, 2022
1 parent 9228839 commit 51afef9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/rpcclient/rpcclient/darwin/hid.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def send_volume_down_button_press(self, interval: int = 0):
def send_volume_up_button_press(self, interval: int = 0):
self.send_key_press(kHIDPage_Consumer, kHIDUsage_Csmr_VolumeIncrement, interval=interval)

def send_key_press(self, page: int, key_code: int, interval: int = 0):
def send_key_press(self, page: int, key_code: int, interval: Union[float, int] = 0):
self.send_keyboard_event(page, key_code, True)
if interval:
time.sleep(interval)
Expand All @@ -100,6 +100,9 @@ def send_keyboard_event(self, page: int, key_code: int, down: bool):
event = self._client.symbols.IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault,
self._client.symbols.mach_absolute_time(),
page, key_code, down, 0)
if not event:
raise BadReturnValueError('IOHIDEventCreateKeyboardEvent() failed')

self.dispatch(event)

def send_swipe_right(self):
Expand Down Expand Up @@ -134,7 +137,6 @@ def send_touch_event(self, event_type: TouchEventType, x: float, y: float, press

child = self.create_digitizer_finger_event(2, 2, event_flags, button_mask, x, y, 0.0, pressure, 0.0,
touch, touch, 0, timestamp=timestamp)

self._client.symbols.IOHIDEventAppendEvent(parent, child)
self.dispatch(parent)

Expand All @@ -148,6 +150,9 @@ def create_digitizer_event(self, type_: Union[IOHIDDigitizerTransducerType, int]
kCFAllocatorDefault, timestamp, type_, index, identity, event_mask,
button_mask, x, y, z, tip_pressure, barrel_pressure, range_, touch, options)

if not event:
raise BadReturnValueError('IOHIDEventCreateDigitizerEvent() failed')

self._client.symbols.IOHIDEventSetIntegerValue(event, IOHIDEventField.kIOHIDEventFieldIsBuiltIn, 0)
self._client.symbols.IOHIDEventSetIntegerValue(
event, IOHIDEventFieldDigitizer.kIOHIDEventFieldDigitizerIsDisplayIntegrated, 1)
Expand All @@ -165,6 +170,9 @@ def create_digitizer_finger_event(self, index: int, identity: int, event_mask: i
kCFAllocatorDefault, timestamp, index, identity, event_mask,
button_mask, x, y, z, tip_pressure, twist, range_, touch, options)

if not event:
raise BadReturnValueError('IOHIDEventCreateDigitizerFingerEvent() failed')

self._client.symbols.IOHIDEventSetFloatValue(
event, IOHIDEventFieldDigitizer.kIOHIDEventFieldDigitizerMajorRadius, 0.5)
return event
Expand Down

0 comments on commit 51afef9

Please sign in to comment.