Skip to content

Repository files navigation

HID-IO layouts Python API

This is the Python API for the HID-IO layouts repository. By default, the API will download the latest version of the layouts git repository to use that as a cache.

The purpose of this API is to acquire and merge the JSON HID layouts. With some additional helpers to deal with string composition.

layouts is also available on PyPi.

pip install layouts

GitHub Action StatusPyPI versionTotal alertsLanguage grade: Python

Visit our IRC channel

Usage

Some basic usage examples.

List Layouts

GitHub Cache

importlayoutsmgr=layouts.Layouts()
print(mgr.list_layouts()

Local Cache

importlayoutslayout_dir="/tmp/mylayouts/layouts"mgr=layouts.Layouts(layout_path=layout_dir)
print(mgr.list_layouts()

Retrieve Layout

importlayoutsmgr=layouts.Layouts()
layout=mgr.get_layout('default')
print(layout.name()) # Name of merged layoutprint(layout.json()) # Fully merged JSON dictprint(layout.locale()) # Tuple (<USB HID locale code>, <name>)

Composition Example

importlayoutsmgr=layouts.Layouts()
layout=mgr.get_layout('default')
input_str="Hello World!"print(layout.compose(input_str))
# Only use code clears when necessary (blank USB packet)print(layout.compose(input_str, minimal_clears=True))

Codes for C-Style Defines

importlayoutsimportlayouts.emittermgr=layouts.Layouts()
layout=mgr.get_layout('default')
# Returns a list of list of tuples# Each type of code has a pre-defined (configurable) prefix# [<keyboard codes>, <led codes>, <system control codes>, <consumer codes>]# (<name>, <code>)# Useful for:# #define KEY_A 0x04print(layouts.emitter.basic_c_defines(layout))

About

Python API for dealing with the layouts repo

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages