-
Notifications
You must be signed in to change notification settings - Fork 2
/
BWHKeyboardHelper.cs
51 lines (36 loc) · 1.5 KB
/
BWHKeyboardHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using BlazorWindowHelper.Classes;
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
using System.Text;
namespace BlazorWindowHelper
{
public static class BWHKeyboardHelper
{
public static BWHKeyboardState keyboardState=new BWHKeyboardState(ConsoleKey.Escape, false,false,false,false);
public static event Action<BWHKeyboardState> OnKeyUp;
public static event Action<BWHKeyboardState> OnKeyDown;
[JSInvokable]
public static void InvokeKeyDown(object args)
{
string[] a = args.ToString().Replace("[", null).Replace("]", null).Split(",");
bool ctrl = bool.Parse(a[1]);
bool shift = bool.Parse(a[2]);
bool alt = bool.Parse(a[3]);
ConsoleKey consoleKey = (ConsoleKey)Enum.Parse(typeof(ConsoleKey), a[0]);
keyboardState = new BWHKeyboardState(consoleKey, ctrl, shift, alt, true);
OnKeyDown?.Invoke(keyboardState);
}
[JSInvokable]
public static void InvokeKeyUp(object args)
{
string[] a = args.ToString().Replace("[", null).Replace("]", null).Split(",");
bool ctrl = bool.Parse(a[1]);
bool shift = bool.Parse(a[2]);
bool alt = bool.Parse(a[3]);
ConsoleKey consoleKey = (ConsoleKey)Enum.Parse(typeof(ConsoleKey), a[0]);
keyboardState = new BWHKeyboardState(consoleKey, ctrl, shift, alt, false);
OnKeyUp?.Invoke(keyboardState);
}
}
}