Skip to content

Commit

Permalink
added keyboard arrowkey support to EitherOr.razor
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGAzed committed Jun 2, 2024
1 parent a4ebfbb commit 6f567cf
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions hiravrt/Views/Pages/Game/EitherOr.razor
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,18 @@
}

@code {
public async void HandleKeypress(KeyboardEventArgs input) {
private async void HandleKeypress(KeyboardEventArgs input) {
Console.WriteLine(input.ToString());
switch (input.Key) {
case "ArrowLeft": case "a": { await checkClick(mc.GameC.EitherOrModel.GuessesPair[0]); break; }
case "ArrowRight": case "d": { await checkClick(mc.GameC.EitherOrModel.GuessesPair[1]); break; }
case "r": { OnReset(); break; }
case "ArrowLeft":
case "a": { await checkClick(mc.GameC.EitherOrModel.GuessesPair[0]); break; }

default: { return; }
case "ArrowRight":
case "d": { await checkClick(mc.GameC.EitherOrModel.GuessesPair[1]); break; }

case "r": { OnReset(); break; }

default: return;
}
StateHasChanged();
}
Expand All @@ -102,7 +107,7 @@
@if (mc.GameC.EitherOrModel.RemainingSyllables.Count < mc.GameC.EitherOrModel.MinimumGuessesCount) {
<Error ErrorNumber="01" ErrorDescription="NOT ENOUGH SYLLABLES TO PLAY GAME" ErrorFix="GO TO SETTINGS TO INCREASE SYLLABLE COUNT" />
} else {
<article class="article-page" id="either-or-gamemode-sub-article" tabindex="0" @onkeypress="HandleKeypress" @ref="gameDiv">
<article class="article-page" id="either-or-gamemode-sub-article" tabindex="0" @onkeydown="HandleKeypress" @ref="gameDiv">
@code {
protected override async Task OnAfterRenderAsync(bool firstRender) {
if (firstRender) await JS.InvokeVoidAsync("SetFocusToElement", gameDiv);
Expand Down

0 comments on commit 6f567cf

Please sign in to comment.