用于HID-IO HID布局存储库的PythonAPI
layouts的Python项目详细描述
hid-io布局python api
这是hid-iolayouts存储库的python api。 默认情况下,api将下载最新版本的layouts git存储库,以将其用作缓存。
此api的目的是获取和合并json hid布局。 用一些额外的助手来处理字符串组合。
layouts也可以在pypi上使用。
pip install layouts
用法
一些基本用法示例。
列表布局
github缓存
importlayoutsmgr=layouts.Layouts()print(mgr.list_layouts()
本地缓存
importlayoutslayout_dir="/tmp/mylayouts/layouts"mgr=layouts.Layouts(layout_path=layout_dir)print(mgr.list_layouts()
检索布局
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>)
构图示例
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))
C样式代码定义
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))