-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
684 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
Prints the scan code of all currently pressed keys. | ||
Updates on every keyboard event. | ||
""" | ||
import sys | ||
sys.path.append('..') | ||
import keyboard | ||
|
||
def print_pressed_keys(e): | ||
line = ', '.join(str(code) for code in keyboard._pressed_events) | ||
# '\r' and end='' overwrites the previous line. | ||
# ' '*40 prints 40 spaces at the end to ensure the previous line is cleared. | ||
print('\r' + line + ' '*40, end='') | ||
|
||
keyboard.hook(print_pressed_keys) | ||
keyboard.wait() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#quick and dirty push-to-talk example for Ubuntu 16.04, by Abd Azrad | ||
|
||
import keyboard | ||
import subprocess | ||
|
||
is_muted = False | ||
|
||
def unmute(): | ||
global is_muted | ||
if not is_muted: # if mic is already enabled | ||
return # do nothing | ||
is_muted = False | ||
subprocess.call('amixer set Capture cap', shell=True) # unmute mic | ||
|
||
def mute(): | ||
global is_muted | ||
is_muted = True | ||
subprocess.call('amixer set Capture nocap', shell=True) # mute mic | ||
|
||
if __name__ == "__main__": | ||
is_muted = True | ||
mute() # mute on startup | ||
|
||
keyboard.add_hotkey('win', unmute) # unmute on keydown | ||
keyboard.add_hotkey('win', mute, trigger_on_release=True) # mute on keyup | ||
|
||
keyboard.wait() # wait forever |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
Prints lines with JSON object for each keyboard event, and reads similar events | ||
from stdin to simulate events. Example: | ||
{"event_type": "down", "name": "a", "scan_code": 30, "time": 1491442622.6348252} | ||
{"event_type": "down", "name": "s", "scan_code": 31, "time": 1491442622.664881} | ||
{"event_type": "down", "name": "d", "scan_code": 32, "time": 1491442622.7148278} | ||
{"event_type": "down", "name": "f", "scan_code": 33, "time": 1491442622.7544951} | ||
{"event_type": "up", "name": "a", "scan_code": 30, "time": 1491442622.7748237} | ||
{"event_type": "up", "name": "s", "scan_code": 31, "time": 1491442622.825077} | ||
{"event_type": "up", "name": "d", "scan_code": 32, "time": 1491442622.8644736} | ||
{"event_type": "up", "name": "f", "scan_code": 33, "time": 1491442622.9056144} | ||
""" | ||
import sys | ||
sys.path.append('..') | ||
|
||
# Also available as just `python -m keyboard`. | ||
from keyboard import __main__ |
Oops, something went wrong.