-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d4887d
commit 6a453ff
Showing
3 changed files
with
78 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<script lang="ts"> | ||
import { useKeyboardControls } from './hooks'; | ||
import type { KeyboardControl } from './models'; | ||
export let config: KeyboardControl[]; | ||
const { UP, f, F, Control_a } = useKeyboardControls(); | ||
let active: string = ''; | ||
$: if ($UP) { | ||
active = 'UP'; | ||
} else if ($f) { | ||
active = 'f'; | ||
} else if ($F) { | ||
active = 'F'; | ||
} else if ($Control_a) { | ||
active = 'Control_a'; | ||
} else { | ||
active = ''; | ||
} | ||
</script> | ||
|
||
<ul> | ||
{#each config as control (control.name)} | ||
<li style:background={active === control.name ? '#3ebf77' : '#eeeeee'}> | ||
<pre>{JSON.stringify(control, null, 2)}</pre> | ||
</li> | ||
{/each} | ||
</ul> | ||
|
||
<style> | ||
ul { | ||
list-style: none; | ||
padding: 0; | ||
/* for testing preventDefault on ArrowUp */ | ||
height: 125vh; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,22 @@ | ||
<h1>Welcome to your library project</h1> | ||
<p>Create your package using @sveltejs/package and preview/showcase your work with SvelteKit</p> | ||
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p> | ||
<script lang="ts"> | ||
import type { KeyboardControl } from "$lib"; | ||
import KeyboardControls from "$lib/KeyboardControls.svelte"; | ||
import Testing from "$lib/Testing.svelte"; | ||
const config: KeyboardControl[] = [ | ||
{ name: 'UP', keys: ['ArrowUp', 'W', 'w'] }, | ||
{ name: 'f', keys: ['f']}, | ||
{ name: 'F', keys: ['F']}, | ||
{ name: 'Control_a', keys: [['Control', 'a']] }, | ||
// { name: 'MetaFCombo', keys: [['Meta', 'f']] }, | ||
] | ||
</script> | ||
|
||
<h1>Svelte Keyboard Controls</h1> | ||
<pre> | ||
<code>npm i -D svelte-kbc</code> | ||
</pre> | ||
<KeyboardControls {config} debug> | ||
<Testing {config} /> | ||
</KeyboardControls> |