0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Svelteでショートカット実装する方法を紹介します。
以下のような実装となります。

<script>
	function onkeydown(event: KeyboardEvent) {
		if (event.key in shortCutKeys) {
			event.preventDefault();
		}
		switch (event.key) {
			case shortCutKeys.Space:
                // 処理
				break;
			case shortCutKeys.Esc:
                // 処理
				break;
		}
	}
</script>

<svelte:window on:keydown={onkeydown} />

ショートカットのキーの場合、preventDefault()が実行されるように実装しています。

全てのキーをprevetDefautlする場合は、以下のように実装します。

<svelte:window on:keydown|preventDefault={onKeyDown} />

因みに、<svelte:window> は色々あるので、時間あるときに確認したいです。
https://learn.svelte.dev/tutorial/svelte-window

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?