134 lines
3.3 KiB
Python
134 lines
3.3 KiB
Python
import sqlite3
|
|
import json
|
|
import uuid
|
|
|
|
def generate_uuid():
|
|
return str(uuid.uuid4())
|
|
|
|
# Configuration for the mappings
|
|
device_id = "75bae499fc7060c40ae424563b660e5122e33c7b"
|
|
device_name = "2.4G Mouse "
|
|
|
|
mappings = [
|
|
# 1. UP
|
|
{
|
|
"trigger_keyCode": 19,
|
|
"trigger_scanCode": 103,
|
|
"action_type": "KEY_EVENT",
|
|
"action_data": "19", # KEYCODE_DPAD_UP
|
|
"action_flags": 4 # Repeat until released
|
|
},
|
|
# 2. DOWN
|
|
{
|
|
"trigger_keyCode": 20,
|
|
"trigger_scanCode": 108,
|
|
"action_type": "KEY_EVENT",
|
|
"action_data": "20", # KEYCODE_DPAD_DOWN
|
|
"action_flags": 4
|
|
},
|
|
# 3. LEFT
|
|
{
|
|
"trigger_keyCode": 21,
|
|
"trigger_scanCode": 105,
|
|
"action_type": "KEY_EVENT",
|
|
"action_data": "21", # KEYCODE_DPAD_LEFT
|
|
"action_flags": 4
|
|
},
|
|
# 4. RIGHT
|
|
{
|
|
"trigger_keyCode": 22,
|
|
"trigger_scanCode": 106,
|
|
"action_type": "KEY_EVENT",
|
|
"action_data": "22", # KEYCODE_DPAD_RIGHT
|
|
"action_flags": 4
|
|
},
|
|
# 5. ENTER (Select)
|
|
{
|
|
"trigger_keyCode": 66,
|
|
"trigger_scanCode": 352,
|
|
"action_type": "KEY_EVENT",
|
|
"action_data": "23", # KEYCODE_DPAD_CENTER
|
|
"action_flags": 0
|
|
},
|
|
# 6. BACK
|
|
{
|
|
"trigger_keyCode": 4,
|
|
"trigger_scanCode": 174,
|
|
"action_type": "KEY_EVENT",
|
|
"action_data": "4", # KEYCODE_BACK
|
|
"action_flags": 0
|
|
},
|
|
# 7. Volume Up (Shutdown)
|
|
{
|
|
"trigger_keyCode": 24,
|
|
"trigger_scanCode": 115,
|
|
"action_type": "SHELL_COMMAND",
|
|
"action_data": "cmVib290IC1w", # base64 for 'reboot -p'
|
|
"action_flags": 0,
|
|
"shell_description": "Shutdown",
|
|
"shell_timeout": "10000"
|
|
}
|
|
]
|
|
|
|
conn = sqlite3.connect('key_map_database')
|
|
cursor = conn.cursor()
|
|
|
|
# Clear existing keymaps
|
|
cursor.execute("DELETE FROM keymaps;")
|
|
|
|
for m in mappings:
|
|
key_uid = generate_uuid()
|
|
trigger_json = {
|
|
"extras": [],
|
|
"flags": 0,
|
|
"keys": [
|
|
{
|
|
"clickType": 0,
|
|
"deviceId": device_id,
|
|
"deviceName": device_name,
|
|
"flags": 0,
|
|
"keyCode": m["trigger_keyCode"],
|
|
"scanCode": m["trigger_scanCode"],
|
|
"uid": key_uid
|
|
}
|
|
],
|
|
"mode": 2
|
|
}
|
|
|
|
action_uid = generate_uuid()
|
|
action_item = {
|
|
"data": m["action_data"],
|
|
"extras": [],
|
|
"flags": m["action_flags"],
|
|
"type": m["action_type"],
|
|
"uid": action_uid
|
|
}
|
|
|
|
if m["action_type"] == "SHELL_COMMAND":
|
|
action_item["extras"] = [
|
|
{"data": m["shell_description"], "id": "extra_shell_command_description"},
|
|
{"data": m["shell_timeout"], "id": "extra_shell_command_timeout"}
|
|
]
|
|
|
|
action_list_json = [action_item]
|
|
|
|
row_uid = generate_uuid()
|
|
|
|
cursor.execute("""
|
|
INSERT INTO keymaps (trigger, action_list, constraint_list, constraint_mode, flags, is_enabled, uid, group_uid)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
""", (
|
|
json.dumps(trigger_json),
|
|
json.dumps(action_list_json),
|
|
"[]",
|
|
1,
|
|
0,
|
|
1,
|
|
row_uid,
|
|
None
|
|
))
|
|
|
|
conn.commit()
|
|
conn.close()
|
|
print("Successfully populated key_map_database!")
|