-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathInputUtils.cs
77 lines (73 loc) · 2.15 KB
/
InputUtils.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;
namespace Holocure_Auto_Fishing_Bot
{
internal static class InputUtils
{
#region DLL Imports
[DllImport("user32.dll")]
private static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
#endregion
#region Fields
private static readonly Dictionary<string, uint> _keyMapping = new Dictionary<string, uint>
{
{ "ENTER", 0x0D },
{ "SHIFT", 0x10 },
{ "CTRL", 0x11 },
{ "ALT", 0x12 },
{ "SPACE", 0x20 },
{ "LEFT", 0x25 },
{ "UP", 0x26 },
{ "RIGHT", 0x27 },
{ "DOWN", 0x28 },
{ "0", 0x30 },
{ "1", 0x31 },
{ "2", 0x32 },
{ "3", 0x33 },
{ "4", 0x34 },
{ "5", 0x35 },
{ "6", 0x36 },
{ "7", 0x37 },
{ "8", 0x38 },
{ "9", 0x39 },
{ "A", 0x41 },
{ "B", 0x42 },
{ "C", 0x43 },
{ "D", 0x44 },
{ "E", 0x45 },
{ "F", 0x46 },
{ "G", 0x47 },
{ "H", 0x48 },
{ "I", 0x49 },
{ "J", 0x4A },
{ "K", 0x4B },
{ "L", 0x4C },
{ "M", 0x4D },
{ "N", 0x4E },
{ "O", 0x4F },
{ "P", 0x50 },
{ "Q", 0x51 },
{ "R", 0x52 },
{ "S", 0x53 },
{ "T", 0x54 },
{ "U", 0x55 },
{ "V", 0x56 },
{ "W", 0x57 },
{ "X", 0x58 },
{ "Y", 0x59 },
{ "Z", 0x5A },
};
#endregion
public static void SendKeyPress(IntPtr hWnd, string key, int duration = 33)
{
const uint WM_KEYDOWN = 0x0100;
const uint WM_KEYUP = 0x0101;
IntPtr key_code = (IntPtr)_keyMapping[key];
PostMessage(hWnd, WM_KEYDOWN, key_code, IntPtr.Zero);
Thread.Sleep(duration);
PostMessage(hWnd, WM_KEYUP, key_code, IntPtr.Zero);
}
}
}