Skip to content

Commit e9a81ba

Browse files
authored
Merge pull request #63 from JPEWdev/consumer-press-release
consumer_control: Add press and release
2 parents 1f4ced5 + c7e1f85 commit e9a81ba

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

adafruit_hid/consumer_control.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,40 @@ def send(self, consumer_code):
6161
# Advance to next track (song).
6262
consumer_control.send(ConsumerControlCode.SCAN_NEXT_TRACK)
6363
"""
64+
self.press(consumer_code)
65+
self.release()
66+
67+
def press(self, consumer_code):
68+
"""Send a report to indicate that the given key has been pressed.
69+
Only one consumer control action can be pressed at a time, so any one
70+
that was previously pressed will be released.
71+
72+
:param consumer_code: a 16-bit consumer control code.
73+
74+
Examples::
75+
76+
from adafruit_hid.consumer_control_code import ConsumerControlCode
77+
78+
# Raise volume for 0.5 seconds
79+
consumer_control.press(ConsumerControlCode.VOLUME_INCREMENT)
80+
time.sleep(0.5)
81+
consumer_control.release()
82+
"""
6483
struct.pack_into("<H", self._report, 0, consumer_code)
6584
self._consumer_device.send_report(self._report)
85+
86+
def release(self):
87+
"""Send a report indicating that the consumer control key has been
88+
released. Only one consumer control key can be pressed at a time.
89+
90+
Examples::
91+
92+
from adafruit_hid.consumer_control_code import ConsumerControlCode
93+
94+
# Raise volume for 0.5 seconds
95+
consumer_control.press(ConsumerControlCode.VOLUME_INCREMENT)
96+
time.sleep(0.5)
97+
consumer_control.release()
98+
"""
6699
self._report[0] = self._report[1] = 0x0
67100
self._consumer_device.send_report(self._report)

0 commit comments

Comments
 (0)