Serpenta Developer Handbook 1.0 Help

Keybinding Engine

The keybinding engine is done via the window event listener. Once the main window is under focused, any configured keyboard click will be recorded and an identifier will be emitted over a Tauri event channel.

On the front-end, an event listener is registered on the event channel shortcut_channel. A parser function will determine which operation shall be taken:

const parseShortCut = async (shortcut:string):Promise<void> => { if (shortcut === "emergency_brake") { console.log("Emergency brake"); await invoke('send_command', { cmdName: "EmergencyBrake", val: 0 }); } else if (shortcut === "heartbeat") { await invoke('send_command', { cmdName: "FrontendHeartbeat", val: 0 }); } }

What's left for the developer to do is emit the event from the Tauri backend with the identifier of the action.

app.emit_all("shortcut_channel", "identifier-here").unwrap();
Last modified: 29 August 2024