Skip to content
Merged
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
23 changes: 0 additions & 23 deletions .coveragerc

This file was deleted.

19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.{yml,yaml,toml,json}]
indent_size = 2

[*.md]
# Trailing whitespace is significant in Markdown, and README.md is generated.
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
31 changes: 12 additions & 19 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
# Auto detect text files and perform LF normalization
# Normalise line endings in the repository, checking out the platform native
# ones. This is what keeps the tree consistent between Windows and Linux.
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
*.py text diff=python
*.md text
*.toml text
*.yml text
*.yaml text
*.txt text
Makefile text

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
# Generated from the directkeys module docstring by the `build` target, so it
# should not count towards language statistics or clutter pull request diffs.
README.md linguist-generated=true
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
commit-message:
prefix: "ci"

- package-ecosystem: pip
directory: /
schedule:
interval: monthly
commit-message:
prefix: "build"
68 changes: 68 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: tests

on:
push:
branches: [master]
pull_request:
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.13'

- uses: astral-sh/ruff-action@v3

- name: Lint
run: ruff check --output-format=github .

- name: Check formatting
run: ruff format --check .

test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# The Linux backend only touches /dev/input from init(), so the suite
# imports and runs unprivileged against the fake backend, as on Windows.
os: [windows-latest, ubuntu-latest]
python-version: ['3.9', '3.11', '3.13']

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install
run: |
python -m pip install --upgrade pip
pip install pytest
pip install -e .

- name: Run tests
# testpaths and norecursedirs come from pyproject.toml.
run: python -m pytest -v

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Build and check the distribution
run: |
python -m pip install --upgrade pip
pip install build twine
python -m build
twine check dist/*
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ eggs/
htmlcov/
coverage_html_report/

# Tooling caches
.ruff_cache/
.mypy_cache/

# Editor and OS specific files
.vscode/
.idea/
Expand All @@ -36,4 +40,4 @@ Desktop.ini
*.bak
*.tmp
*.swp
*~.nib
*~.nib
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.16.1
hooks:
- id: ruff-check
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: trailing-whitespace
# README.md is generated from the __init__ docstring; leave it alone.
exclude: ^README\.md$
- id: end-of-file-fixer
exclude: ^README\.md$
- id: check-yaml
- id: check-toml
- id: check-merge-conflict
- id: check-added-large-files
45 changes: 45 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
# 1.0.0

First release of `directkeys`, a fork of [boppreh/keyboard](https://github.com/boppreh/keyboard) 0.13.5.
The API is unchanged, so migrating is usually just a matter of changing the import.

New features:

- [Windows] Configurable AltGr abstraction via `set_alt_gr_abstraction()` and
`get_alt_gr_abstraction_state()`. Enabled by default, it reports the
Right Alt + synthetic Left Ctrl pair as a single `alt gr` event; disable it
to see the raw events.
- [Windows] `get_stuck_keys()` reports modifiers left held down, and
`force_reset_keyboard()` releases them. Useful after a program crashes
without releasing a key it pressed.
- `KeyboardEvent.flags` exposes the low-level hook flags, and is included in
`to_json()`. On Windows it currently carries the `LLKHF_EXTENDED` bit.

Also exposes `__version__` as the canonical version attribute. The upstream
`version` name is kept as an alias, so nothing breaks.

Packaging and project layout:

- Renamed the package and the distribution to `directkeys`.
- **Python 3.9+ is now required.** 3.8 reached end of life in October 2024.
All the Python 2 compatibility shims are gone with it.
- Metadata moved to `pyproject.toml`; `setup.py` is now only a shim.
- The package moved to a `src/` layout, so the test run exercises the
installed distribution rather than the source tree.
- Ruff (lint and format), pre-commit and an EditorConfig are configured, and
CI runs the suite plus a lint and a build check on Windows and Linux.

Fixes carried over from the initial fork work:

- `force_reset_keyboard()`, `get_stuck_keys()` and `reset_internal_state()`
were never loaded from the Windows backend and always resolved to no-op
stubs.
- `get_modifiers()` built a 32772-element tuple on every keystroke whenever
shift was held, because `GetKeyState` reports the pressed bit as `0x8000`.
- `set_alt_gr_abstraction()` never rebuilt the name tables.
- Key events reported `is_keypad` as the extended-key flag, which is close to
the inverse of the intended value, and dropped the `scan_code or -vk`
fallback for keys with no scan code.
- Importing the package on macOS no longer fails when pyobjc is missing.


# 0.13.5

- Added LICENSE.txt file to PyPI packages.
Expand Down
1 change: 1 addition & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2016 BoppreH
Copyright (c) 2025 WigoWigo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include CHANGES.md
include README.md
include LICENSE.txt
include LICENSE.txt
include pyproject.toml
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
test:
python -m pytest tests/ --cov=directkeys --cov-report=html
python -m pytest --cov=directkeys --cov-report=html

build: tests directkeys setup.py README.md CHANGES.md MANIFEST.in
lint:
python -m ruff check .
python -m ruff format --check .

format:
python -m ruff check --fix .
python -m ruff format .

build: tests src/directkeys pyproject.toml README.md CHANGES.md MANIFEST.in
python ../docstring2markdown/docstring2markdown.py directkeys "https://github.com/WigoWigo10/keyboard/blob/master" > README.md
find . \( -name "*.py" -o -name "*.sh" -o -name "* .md" \) -exec dos2unix {} \;
python setup.py sdist --format=zip bdist_wheel && twine check dist/*
python -m build && twine check dist/*

release:
python make_release.py

clean:
rm -rfv dist build coverage_html_report directkeys.egg-info
rm -rfv dist build coverage_html_report directkeys.egg-info
Loading
Loading