Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ local.properties
## TODO: If you have NuGet Package Restore enabled, uncomment this
#packages/

# VSCode Settings
.vscode/

# Visual C++ cache files
ipch/
*.aps
Expand Down Expand Up @@ -136,6 +139,8 @@ Desktop.ini
#############

*.py[co]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arquivos de cache do Visual C ++ # Arquivos de cache do Visual C ++

ipch / ipch /

  • .aps * .aps
    @@ -136,6 +139,8 @@ Desktop.ini

############ #

  • .py [ co ]

venv/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.envrc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.envrc
.envrc


# Packages
*.egg
Expand Down
26 changes: 13 additions & 13 deletions keyboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
- Key suppression/blocking only available on Windows. [#22](https://github.com/boppreh/keyboard/issues/22)
- To avoid depending on X, the Linux parts reads raw device files (`/dev/input/input*`)
but this requires root.
- Other applications, such as some games, may register hooks that swallow all
- Other applications, such as some games, may register hooks that swallow all
key events. In this case `keyboard` will be unable to report events.
- This program makes no attempt to hide itself, so don't use it for keyloggers or online gaming bots. Be responsible.
"""
Expand Down Expand Up @@ -140,7 +140,7 @@ def is_modifier(key):
return key in all_modifiers
else:
if not _modifier_scan_codes:
scan_codes = (key_to_scan_codes(name, False) for name in all_modifiers)
scan_codes = (key_to_scan_codes(name, False) for name in all_modifiers)
_modifier_scan_codes.update(*scan_codes)
return key in _modifier_scan_codes

Expand Down Expand Up @@ -418,7 +418,7 @@ def is_pressed(hotkey):
if len(steps) > 1:
raise ValueError("Impossible to check if multi-step hotkeys are pressed (`a+b` is ok, `a, b` isn't).")

# Convert _pressed_events into a set
# Convert _pressed_events into a set
with _pressed_events_lock:
pressed_scan_codes = set(_pressed_events)
for scan_codes in steps[0]:
Expand All @@ -440,7 +440,7 @@ def hook(callback, suppress=False, on_remove=lambda: None):
"""
Installs a global listener on all available keyboards, invoking `callback`
each time a key is pressed or released.

The event passed to the callback is of type `keyboard.KeyboardEvent`,
with the following attributes:

Expand Down Expand Up @@ -579,7 +579,7 @@ def _add_hotkey_step(handler, combinations, suppress):
container = _listener.blocking_hotkeys if suppress else _listener.nonblocking_hotkeys

# Register the scan codes of every possible combination of
# modfiier + main key. Modifiers have to be registered in
# modfiier + main key. Modifiers have to be registered in
# filtered_modifiers too, so suppression and replaying can work.
for scan_codes in combinations:
for scan_code in scan_codes:
Expand Down Expand Up @@ -663,7 +663,7 @@ def remove_():
state.remove_last_step = None
state.suppressed_events = []
state.last_update = float('-inf')

def catch_misses(event, force_fail=False):
if (
event.event_type == event_type
Expand Down Expand Up @@ -704,7 +704,7 @@ def handler(event):
if event.event_type == KEY_UP:
remove()
set_index(0)
accept = event.event_type == event_type and callback()
accept = event.event_type == event_type and callback()
if accept:
return catch_misses(event, force_fail=True)
else:
Expand Down Expand Up @@ -838,7 +838,7 @@ def write(text, delay=0, restore_state_after=True, exact=None):
exact = _platform.system() == 'Windows'

state = stash_state()

# Window's typing of unicode characters is quite efficient and should be preferred.
if exact:
for letter in text:
Expand All @@ -855,7 +855,7 @@ def write(text, delay=0, restore_state_after=True, exact=None):
except (KeyError, ValueError):
_os_keyboard.type_unicode(letter)
continue

for modifier in modifiers:
press(modifier)

Expand Down Expand Up @@ -909,11 +909,11 @@ def get_hotkey_name(names=None):
else:
names = [normalize_name(name) for name in names]
clean_names = set(e.replace('left ', '').replace('right ', '').replace('+', 'plus') for e in names)
# https://developer.apple.com/macos/human-interface-guidelines/input-and-output/keyboard/
# https://developer.apple.com/design/human-interface-guidelines/macos/user-interaction/keyboard/
# > List modifier keys in the correct order. If you use more than one modifier key in a
# > hotkey, always list them in this order: Control, Option, Shift, Command.
modifiers = ['ctrl', 'alt', 'shift', 'windows']
sorting_key = lambda k: (modifiers.index(k) if k in modifiers else 5, str(k))
modifiers = [normalize_name(key) for key in ['ctrl', 'alt', 'shift', 'windows']]
sorting_key = lambda k: (modifiers.index(k) if k in modifiers else len(modifiers), str(k))
return '+'.join(sorted(clean_names, key=sorting_key))

def read_event(suppress=False):
Expand Down Expand Up @@ -1144,7 +1144,7 @@ def add_abbreviation(source_text, replacement_text, match_suffix=False, timeout=
listener for 'pet'. Defaults to false, only whole words are checked.
- `timeout` is the maximum number of seconds between typed characters before
the current word is discarded. Defaults to 2 seconds.

For more details see `add_word_listener`.
"""
replacement = '\b'*(len(source_text)+1) + replacement_text
Expand Down
4 changes: 3 additions & 1 deletion keyboard/_canonical_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,9 @@
"cmd": "command",
"win": "command",
"backspace": "delete",
'alt gr': 'alt' # Issue #117
"alt gr": "option", # Issue #117,
"alt": "option",
"enter": "return",
})
all_modifiers = {'alt', 'ctrl', 'shift', 'windows'}
if platform.system() == 'Linux':
Expand Down