Skip to main content

No project description provided

Project description

AnalogSense Python SDK

Python port of AnalogSense.js for analog keyboard input.

Supported Keyboards/Devices

  • Everything by Wooting
  • Everything by NuPhy
  • Everything by DrunkDeer
  • Razer Huntsman V2 AnalogR
  • Razer Huntsman Mini AnalogR
  • Razer Huntsman V3 ProR
  • Razer Huntsman V3 Pro MiniR
  • Razer Huntsman V3 Pro TenkeylessR
  • Keychron Q1 HEP, F
  • Keychron Q3 HEP, F
  • Keychron Q5 HEP, F
  • Keychron K2 HEP, F
  • Lemokey P1 HEP, F
  • Madlions MAD60HEP
  • Madlions MAD68HEP
  • Madlions MAD68RP
  • Redragon K709HEP

R Razer Synapse needs to be installed and running for analogue inputs to be received from this keyboard.
P The official firmware only supports polling, which can lead to lag and missed inputs.
F Custom firmware with full analog report functionality is available.

Installation

pip install AnalogSensePy

On Linux you may need udev rules or sudo for hid

printf '%s\n' \
  'KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0660", GROUP="input"' \
  'SUBSYSTEM=="usb", ATTRS{idVendor}=="31e3", MODE="0660", GROUP="input"' \
  'SUBSYSTEM=="usb", ATTRS{idVendor}=="03eb", MODE="0660", GROUP="input"' \
  'SUBSYSTEM=="usb", ATTRS{idVendor}=="1532", MODE="0660", GROUP="input"' \
  'SUBSYSTEM=="usb", ATTRS{idVendor}=="19f5", MODE="0660", GROUP="input"' \
  'SUBSYSTEM=="usb", ATTRS{idVendor}=="352d", MODE="0660", GROUP="input"' \
  'SUBSYSTEM=="usb", ATTRS{idVendor}=="3434", MODE="0660", GROUP="input"' \
  'SUBSYSTEM=="usb", ATTRS{idVendor}=="362d", MODE="0660", GROUP="input"' \
  'SUBSYSTEM=="usb", ATTRS{idVendor}=="373b", MODE="0660", GROUP="input"' \
  'SUBSYSTEM=="usb", ATTRS{idVendor}=="372e", MODE="0660", GROUP="input"' \
  | sudo tee /etc/udev/rules.d/99-analogsense.rules

sudo udevadm control --reload-rules && sudo udevadm trigger

Usage

from analogsense import AnalogSense

as_ = AnalogSense()
devices = as_.get_devices()

if not devices:
    print("no supported analog keyboards found.")
    exit()

if len(devices) == 1:
    dev = devices[0]
else:
    for i, d in enumerate(devices):
        print(f"  [{i}] {d.product_name}")
    dev = devices[int(input("select device index: "))]

def on_keys(active_keys):
    for k in active_keys:
        # converting the scancode to a nice readable string
        name = as_.scancode_to_string(k["scancode"])
        
        # some providers can return the digital state of the key
        # (what the system perceives the key as pressed or not)
        # other providers that do not support this will return None
        if k["digital"] is not None:
            digital = " [down]" if k["digital"] else " [up]"
        else:
            digital = ""

        print(f"{name:20s} {k['value']:.4f}{digital}")

dev.start_listening(on_keys)
input("press keys... enter to stop.\n")
dev.stop_listening()

The following functions are available on AnalogSense:

  • get_devices() -> list[Device]
  • open_device(vendor_id, product_id) -> Device | None
  • scancode_to_string(scancode: int) -> str

A device instance has the following members:

  • start_listening(handler: Callable[[list[{"scancode": int, "value": float}]], None])
  • stop_listening()
  • product_name: str
  • forget()
  • dev: DeviceHandle

Scancodes

The scancodes provided by this library are primarily HID scancodes; most keys are mapped as seen on usage page 0x07 (A = 0x04, B = 0x05, ...).

Control keys (usage page 0x0C) are mapped in the 0x3__ range, modulo 0x100:

  • 0x3B5 = Next Track
  • 0x3B6 = Previous Track
  • 0x3B7 = Stop Media
  • 0x3CD = Play/Pause
  • 0x394 = Open File Explorer
  • 0x323 = Open Browser Home Page

OEM-specific keys are mapped in the 0x4__ range:

  • 0x401 = Brightness Up
  • 0x402 = Brightness Down
  • 0x403 = Profile 1
  • 0x404 = Profile 2
  • 0x405 = Profile 3
  • 0x408 = Profile Switch
  • 0x409 = Function Key (Fn)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

analogsensepy-1.0.6.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

analogsensepy-1.0.6-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file analogsensepy-1.0.6.tar.gz.

File metadata

  • Download URL: analogsensepy-1.0.6.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for analogsensepy-1.0.6.tar.gz
Algorithm Hash digest
SHA256 5366b1a8478a9720ba80069d5f093d2be25eec0180248a1eb4b74e0081f2e6b1
MD5 742ab792404a343eb7858869a155d260
BLAKE2b-256 186b4be5c7d8043acb8859d4f5f169b8599efdcea9dfb80328f4fb352891f931

See more details on using hashes here.

Provenance

The following attestation bundles were made for analogsensepy-1.0.6.tar.gz:

Publisher: publish.yml on girlglock/AnalogSense-Python-SDK

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file analogsensepy-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: analogsensepy-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for analogsensepy-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 6f694e72c66bb58ab19a3b18ad44adde1f69d8df2936f27e5b8e2dade7875ac5
MD5 7f0cb34c7ecaf633f0da857ec3e0eccc
BLAKE2b-256 875fe97783bdeb04ec9220315388a780cacf29bbd7657573202f4a5103f26830

See more details on using hashes here.

Provenance

The following attestation bundles were made for analogsensepy-1.0.6-py3-none-any.whl:

Publisher: publish.yml on girlglock/AnalogSense-Python-SDK

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page