-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKeyboard.cs
More file actions
56 lines (45 loc) · 1.53 KB
/
Copy pathKeyboard.cs
File metadata and controls
56 lines (45 loc) · 1.53 KB
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
52
53
54
55
56
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using ExileCore;
using ExileCore.Shared;
namespace AreWeThereYet;
public static class Keyboard
{
private const string CoroutineKeyPress = "KeyPress";
private static Coroutine _keyboardCoroutine;
private const int KeyeventfExtendedkey = 0x0001;
private const int KeyeventfKeyup = 0x0002;
[DllImport("user32.dll")]
private static extern uint keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
[DllImport("user32.dll")]
public static extern bool BlockInput(bool fBlockIt);
public static void KeyDown(Keys key)
{
keybd_event((byte) key, 0, KeyeventfExtendedkey | 0, 0);
}
public static void KeyUp(Keys key)
{
keybd_event((byte) key, 0, KeyeventfExtendedkey | KeyeventfKeyup, 0); //0x7F
}
[DllImport("USER32.dll")]
private static extern short GetKeyState(int nVirtKey);
public static bool IsKeyDown(int nVirtKey)
{
return GetKeyState(nVirtKey) < 0;
}
public static void KeyPress(Keys key, bool anyDelay = true)
{
if (anyDelay)
AreWeThereYet.Instance.lastTimeAny = DateTime.Now;
_keyboardCoroutine = new Coroutine(KeyPressRoutine(key), AreWeThereYet.Instance, CoroutineKeyPress);
Core.ParallelRunner.Run(_keyboardCoroutine);
}
private static IEnumerator KeyPressRoutine(Keys key)
{
KeyDown(key);
yield return new WaitTime(20);
KeyUp(key);
}
}