Skip to content

Commit

Permalink
feat: basic keyboard UI component
Browse files Browse the repository at this point in the history
  • Loading branch information
ABeltramo committed Apr 17, 2024
1 parent d6eeb34 commit fb1a9fa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/server/web-client/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Mouse from "./lib/Mouse.svelte";
import {Toolbar, ToolbarGroup, DarkMode, Toast} from 'flowbite-svelte';
import {FireOutline} from "flowbite-svelte-icons";
import Keyboard from "./lib/Keyboard.svelte";
</script>

<main>
Expand All @@ -24,6 +25,10 @@
<Mouse/>
{/if}

{#if $selected_device?.type === "KEYBOARD"}
<Keyboard/>
{/if}

<FetchRequest/>
</main>

Expand Down
29 changes: 29 additions & 0 deletions src/server/web-client/src/lib/Keyboard.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script lang="ts">
import {request, selected_device} from "./stores";
import {onDestroy, onMount} from "svelte";
function keydown(e: KeyboardEvent) {
if ($selected_device?.type === "KEYBOARD") {
request("/devices/keyboard/" + $selected_device?.device_id + "/press", "POST", {
"key": 65 // hardcoded a
// TODO: e.key to win32 keycode
// see: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
});
// TODO: check for shift, ctrl, alt, etc..
}
}
function keyup(e: KeyboardEvent) {
if ($selected_device?.type === "KEYBOARD") {
request("/devices/keyboard/" + $selected_device?.device_id + "/release", "POST", {
"key": 65 // hardcoded a
})
}
}
</script>

<input on:keydown={keydown}
on:keyup={keyup}>

0 comments on commit fb1a9fa

Please sign in to comment.