scripts
This commit is contained in:
@@ -0,0 +1,219 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace WindowsInput
|
||||
{
|
||||
// Token: 0x02000009 RID: 9
|
||||
public static class InputSimulator
|
||||
{
|
||||
// Token: 0x06000001 RID: 1
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern uint SendInput(uint numberOfInputs, INPUT[] inputs, int sizeOfInputStructure);
|
||||
|
||||
// Token: 0x06000002 RID: 2
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern short GetAsyncKeyState(ushort virtualKeyCode);
|
||||
|
||||
// Token: 0x06000003 RID: 3
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern short GetKeyState(ushort virtualKeyCode);
|
||||
|
||||
// Token: 0x06000004 RID: 4
|
||||
[DllImport("user32.dll")]
|
||||
private static extern IntPtr GetMessageExtraInfo();
|
||||
|
||||
// Token: 0x06000005 RID: 5 RVA: 0x00002050 File Offset: 0x00000250
|
||||
public static bool IsKeyDownAsync(VirtualKeyCode keyCode)
|
||||
{
|
||||
short asyncKeyState = InputSimulator.GetAsyncKeyState((ushort)keyCode);
|
||||
return asyncKeyState < 0;
|
||||
}
|
||||
|
||||
// Token: 0x06000006 RID: 6 RVA: 0x00002070 File Offset: 0x00000270
|
||||
public static bool IsKeyDown(VirtualKeyCode keyCode)
|
||||
{
|
||||
short keyState = InputSimulator.GetKeyState((ushort)keyCode);
|
||||
return keyState < 0;
|
||||
}
|
||||
|
||||
// Token: 0x06000007 RID: 7 RVA: 0x00002090 File Offset: 0x00000290
|
||||
public static bool IsTogglingKeyInEffect(VirtualKeyCode keyCode)
|
||||
{
|
||||
short keyState = InputSimulator.GetKeyState((ushort)keyCode);
|
||||
return (keyState & 1) == 1;
|
||||
}
|
||||
|
||||
// Token: 0x06000008 RID: 8 RVA: 0x000020B0 File Offset: 0x000002B0
|
||||
public static void SimulateKeyDown(VirtualKeyCode keyCode)
|
||||
{
|
||||
INPUT input = default(INPUT);
|
||||
input.Type = 1U;
|
||||
input.Data.Keyboard = default(KEYBDINPUT);
|
||||
input.Data.Keyboard.Vk = (ushort)keyCode;
|
||||
input.Data.Keyboard.Scan = 0;
|
||||
input.Data.Keyboard.Flags = 0U;
|
||||
input.Data.Keyboard.Time = 0U;
|
||||
input.Data.Keyboard.ExtraInfo = IntPtr.Zero;
|
||||
uint num = InputSimulator.SendInput(1U, new INPUT[] { input }, Marshal.SizeOf(typeof(INPUT)));
|
||||
if (num == 0U)
|
||||
{
|
||||
throw new Exception(string.Format("The key down simulation for {0} was not successful.", keyCode));
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000009 RID: 9 RVA: 0x0000218C File Offset: 0x0000038C
|
||||
public static void SimulateKeyUp(VirtualKeyCode keyCode)
|
||||
{
|
||||
INPUT input = default(INPUT);
|
||||
input.Type = 1U;
|
||||
input.Data.Keyboard = default(KEYBDINPUT);
|
||||
input.Data.Keyboard.Vk = (ushort)keyCode;
|
||||
input.Data.Keyboard.Scan = 0;
|
||||
input.Data.Keyboard.Flags = 2U;
|
||||
input.Data.Keyboard.Time = 0U;
|
||||
input.Data.Keyboard.ExtraInfo = IntPtr.Zero;
|
||||
uint num = InputSimulator.SendInput(1U, new INPUT[] { input }, Marshal.SizeOf(typeof(INPUT)));
|
||||
if (num == 0U)
|
||||
{
|
||||
throw new Exception(string.Format("The key up simulation for {0} was not successful.", keyCode));
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600000A RID: 10 RVA: 0x00002268 File Offset: 0x00000468
|
||||
public static void SimulateKeyPress(VirtualKeyCode keyCode)
|
||||
{
|
||||
INPUT input = default(INPUT);
|
||||
input.Type = 1U;
|
||||
input.Data.Keyboard = default(KEYBDINPUT);
|
||||
input.Data.Keyboard.Vk = (ushort)keyCode;
|
||||
input.Data.Keyboard.Scan = 0;
|
||||
input.Data.Keyboard.Flags = 0U;
|
||||
input.Data.Keyboard.Time = 0U;
|
||||
input.Data.Keyboard.ExtraInfo = IntPtr.Zero;
|
||||
INPUT input2 = default(INPUT);
|
||||
input2.Type = 1U;
|
||||
input2.Data.Keyboard = default(KEYBDINPUT);
|
||||
input2.Data.Keyboard.Vk = (ushort)keyCode;
|
||||
input2.Data.Keyboard.Scan = 0;
|
||||
input2.Data.Keyboard.Flags = 2U;
|
||||
input2.Data.Keyboard.Time = 0U;
|
||||
input2.Data.Keyboard.ExtraInfo = IntPtr.Zero;
|
||||
uint num = InputSimulator.SendInput(2U, new INPUT[] { input, input2 }, Marshal.SizeOf(typeof(INPUT)));
|
||||
if (num == 0U)
|
||||
{
|
||||
throw new Exception(string.Format("The key press simulation for {0} was not successful.", keyCode));
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600000B RID: 11 RVA: 0x000023D4 File Offset: 0x000005D4
|
||||
public static void SimulateTextEntry(string text)
|
||||
{
|
||||
if ((long)text.Length > 2147483647L)
|
||||
{
|
||||
throw new ArgumentException(string.Format("The text parameter is too long. It must be less than {0} characters.", 2147483647U), "text");
|
||||
}
|
||||
byte[] bytes = Encoding.ASCII.GetBytes(text);
|
||||
int num = bytes.Length;
|
||||
INPUT[] array = new INPUT[num * 2];
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
ushort num2 = (ushort)bytes[i];
|
||||
INPUT input = default(INPUT);
|
||||
input.Type = 1U;
|
||||
input.Data.Keyboard = default(KEYBDINPUT);
|
||||
input.Data.Keyboard.Vk = 0;
|
||||
input.Data.Keyboard.Scan = num2;
|
||||
input.Data.Keyboard.Flags = 4U;
|
||||
input.Data.Keyboard.Time = 0U;
|
||||
input.Data.Keyboard.ExtraInfo = IntPtr.Zero;
|
||||
INPUT input2 = default(INPUT);
|
||||
input2.Type = 1U;
|
||||
input2.Data.Keyboard = default(KEYBDINPUT);
|
||||
input2.Data.Keyboard.Vk = 0;
|
||||
input2.Data.Keyboard.Scan = num2;
|
||||
input2.Data.Keyboard.Flags = 6U;
|
||||
input2.Data.Keyboard.Time = 0U;
|
||||
input2.Data.Keyboard.ExtraInfo = IntPtr.Zero;
|
||||
if ((num2 & 65280) == 57344)
|
||||
{
|
||||
input.Data.Keyboard.Flags = input.Data.Keyboard.Flags | 1U;
|
||||
input2.Data.Keyboard.Flags = input2.Data.Keyboard.Flags | 1U;
|
||||
}
|
||||
array[2 * i] = input;
|
||||
array[2 * i + 1] = input2;
|
||||
}
|
||||
uint num3 = InputSimulator.SendInput((uint)(num * 2), array, Marshal.SizeOf(typeof(INPUT)));
|
||||
}
|
||||
|
||||
// Token: 0x0600000C RID: 12 RVA: 0x000025DB File Offset: 0x000007DB
|
||||
public static void SimulateModifiedKeyStroke(VirtualKeyCode modifierKeyCode, VirtualKeyCode keyCode)
|
||||
{
|
||||
InputSimulator.SimulateKeyDown(modifierKeyCode);
|
||||
InputSimulator.SimulateKeyPress(keyCode);
|
||||
InputSimulator.SimulateKeyUp(modifierKeyCode);
|
||||
}
|
||||
|
||||
// Token: 0x0600000D RID: 13 RVA: 0x00002608 File Offset: 0x00000808
|
||||
public static void SimulateModifiedKeyStroke(IEnumerable<VirtualKeyCode> modifierKeyCodes, VirtualKeyCode keyCode)
|
||||
{
|
||||
if (modifierKeyCodes != null)
|
||||
{
|
||||
modifierKeyCodes.ToList<VirtualKeyCode>().ForEach(delegate(VirtualKeyCode x)
|
||||
{
|
||||
InputSimulator.SimulateKeyDown(x);
|
||||
});
|
||||
}
|
||||
InputSimulator.SimulateKeyPress(keyCode);
|
||||
if (modifierKeyCodes != null)
|
||||
{
|
||||
modifierKeyCodes.Reverse<VirtualKeyCode>().ToList<VirtualKeyCode>().ForEach(delegate(VirtualKeyCode x)
|
||||
{
|
||||
InputSimulator.SimulateKeyUp(x);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600000E RID: 14 RVA: 0x00002694 File Offset: 0x00000894
|
||||
public static void SimulateModifiedKeyStroke(VirtualKeyCode modifierKey, IEnumerable<VirtualKeyCode> keyCodes)
|
||||
{
|
||||
InputSimulator.SimulateKeyDown(modifierKey);
|
||||
if (keyCodes != null)
|
||||
{
|
||||
keyCodes.ToList<VirtualKeyCode>().ForEach(delegate(VirtualKeyCode x)
|
||||
{
|
||||
InputSimulator.SimulateKeyPress(x);
|
||||
});
|
||||
}
|
||||
InputSimulator.SimulateKeyUp(modifierKey);
|
||||
}
|
||||
|
||||
// Token: 0x0600000F RID: 15 RVA: 0x00002700 File Offset: 0x00000900
|
||||
public static void SimulateModifiedKeyStroke(IEnumerable<VirtualKeyCode> modifierKeyCodes, IEnumerable<VirtualKeyCode> keyCodes)
|
||||
{
|
||||
if (modifierKeyCodes != null)
|
||||
{
|
||||
modifierKeyCodes.ToList<VirtualKeyCode>().ForEach(delegate(VirtualKeyCode x)
|
||||
{
|
||||
InputSimulator.SimulateKeyDown(x);
|
||||
});
|
||||
}
|
||||
if (keyCodes != null)
|
||||
{
|
||||
keyCodes.ToList<VirtualKeyCode>().ForEach(delegate(VirtualKeyCode x)
|
||||
{
|
||||
InputSimulator.SimulateKeyPress(x);
|
||||
});
|
||||
}
|
||||
if (modifierKeyCodes != null)
|
||||
{
|
||||
modifierKeyCodes.Reverse<VirtualKeyCode>().ToList<VirtualKeyCode>().ForEach(delegate(VirtualKeyCode x)
|
||||
{
|
||||
InputSimulator.SimulateKeyUp(x);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user