Add Project
This commit is contained in:
172
NativeMethods.cs
Executable file
172
NativeMethods.cs
Executable file
@ -0,0 +1,172 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace MacroBoard.Native
|
||||
{
|
||||
public static class Messages
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern bool PeekMessage(
|
||||
out NativeMessage lpMsg,
|
||||
IntPtr hwnd,
|
||||
uint wMsgFilterMin,
|
||||
uint wMsgFilterMax,
|
||||
uint wRemoveMsg);
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct NativeMessage
|
||||
{
|
||||
public IntPtr handle;
|
||||
public uint msg;
|
||||
public IntPtr wParam;
|
||||
public IntPtr lParam;
|
||||
public uint time;
|
||||
public System.Drawing.Point p;
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum PeekMessageParams : uint
|
||||
{
|
||||
PM_NOREMOVE = 0x0000,
|
||||
PM_REMOVE = 0x0001,
|
||||
PM_NOYIELD = 0x0002,
|
||||
PM_QS_INPUT = QueueStatusFlags.QS_INPUT << 16,
|
||||
PM_QS_POSTMESSAGE = (QueueStatusFlags.QS_POSTMESSAGE | QueueStatusFlags.QS_HOTKEY | QueueStatusFlags.QS_TIMER) << 16,
|
||||
PM_QS_PAINT = QueueStatusFlags.QS_PAINT << 16,
|
||||
PM_QS_SENDMESSAGE = QueueStatusFlags.QS_SENDMESSAGE << 16
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum QueueStatusFlags : uint
|
||||
{
|
||||
QS_KEY = 0x1,
|
||||
QS_MOUSEMOVE = 0x2,
|
||||
QS_MOUSEBUTTON = 0x4,
|
||||
QS_MOUSE = (QS_MOUSEMOVE | QS_MOUSEBUTTON),
|
||||
QS_INPUT = (QS_MOUSE | QS_KEY),
|
||||
QS_POSTMESSAGE = 0x8,
|
||||
QS_TIMER = 0x10,
|
||||
QS_PAINT = 0x20,
|
||||
QS_SENDMESSAGE = 0x40,
|
||||
QS_HOTKEY = 0x80,
|
||||
QS_REFRESH = (QS_HOTKEY | QS_KEY | QS_MOUSEBUTTON | QS_PAINT),
|
||||
QS_ALLEVENTS = (QS_INPUT | QS_POSTMESSAGE | QS_TIMER | QS_PAINT | QS_HOTKEY),
|
||||
QS_ALLINPUT = (QS_SENDMESSAGE | QS_PAINT | QS_TIMER | QS_POSTMESSAGE | QS_MOUSEBUTTON | QS_MOUSEMOVE | QS_HOTKEY | QS_KEY),
|
||||
QS_ALLPOSTMESSAGE = 0x100,
|
||||
QS_RAWINPUT = 0x400
|
||||
}
|
||||
|
||||
|
||||
public enum AppComandCode : uint
|
||||
{
|
||||
BASS_BOOST = 20,
|
||||
BASS_DOWN = 19,
|
||||
BASS_UP = 21,
|
||||
BROWSER_BACKWARD = 1,
|
||||
BROWSER_FAVORITES = 6,
|
||||
BROWSER_FORWARD = 2,
|
||||
BROWSER_HOME = 7,
|
||||
BROWSER_REFRESH = 3,
|
||||
BROWSER_SEARCH = 5,
|
||||
BROWSER_STOP = 4,
|
||||
LAUNCH_APP1 = 17,
|
||||
LAUNCH_APP2 = 18,
|
||||
LAUNCH_MAIL = 15,
|
||||
LAUNCH_MEDIA_SELECT = 16,
|
||||
MEDIA_NEXTTRACK = 11,
|
||||
MEDIA_PLAY_PAUSE = 14,
|
||||
MEDIA_PREVIOUSTRACK = 12,
|
||||
MEDIA_STOP = 13,
|
||||
TREBLE_DOWN = 22,
|
||||
TREBLE_UP = 23,
|
||||
VOLUME_DOWN = 9,
|
||||
VOLUME_MUTE = 8,
|
||||
VOLUME_UP = 10,
|
||||
MICROPHONE_VOLUME_MUTE = 24,
|
||||
MICROPHONE_VOLUME_DOWN = 25,
|
||||
MICROPHONE_VOLUME_UP = 26,
|
||||
CLOSE = 31,
|
||||
COPY = 36,
|
||||
CORRECTION_LIST = 45,
|
||||
CUT = 37,
|
||||
DICTATE_OR_COMMAND_CONTROL_TOGGLE = 43,
|
||||
FIND = 28,
|
||||
FORWARD_MAIL = 40,
|
||||
HELP = 27,
|
||||
MEDIA_CHANNEL_DOWN = 52,
|
||||
MEDIA_CHANNEL_UP = 51,
|
||||
MEDIA_FASTFORWARD = 49,
|
||||
MEDIA_PAUSE = 47,
|
||||
MEDIA_PLAY = 46,
|
||||
MEDIA_RECORD = 48,
|
||||
MEDIA_REWIND = 50,
|
||||
MIC_ON_OFF_TOGGLE = 44,
|
||||
NEW = 29,
|
||||
OPEN = 30,
|
||||
PASTE = 38,
|
||||
PRINT = 33,
|
||||
REDO = 35,
|
||||
REPLY_TO_MAIL = 39,
|
||||
SAVE = 32,
|
||||
SEND_MAIL = 41,
|
||||
SPELL_CHECK = 42,
|
||||
UNDO = 34,
|
||||
DELETE = 53,
|
||||
DWM_FLIP3D = 54
|
||||
}
|
||||
}
|
||||
|
||||
public static class Libraries
|
||||
{
|
||||
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
|
||||
public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName);
|
||||
|
||||
[DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
|
||||
public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
|
||||
}
|
||||
|
||||
public static class Windows
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr FindWindow(string strClassName, string strWindowName);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
|
||||
}
|
||||
|
||||
public static class Keyboards
|
||||
{
|
||||
public const uint KEYEVENTF_EXTENDEDKEY = 0x0001;
|
||||
public const uint KEYEVENTF_KEYUP = 0x0002;
|
||||
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
|
||||
public static extern short GetKeyState(int keyCode);
|
||||
|
||||
public static bool IsNumLockEnabled() => (((ushort)GetKeyState(0x90)) & 0xFFFF) != 0;
|
||||
|
||||
public enum KeyState
|
||||
{
|
||||
Down,
|
||||
Up
|
||||
}
|
||||
|
||||
//There is a built in System.Windows.Input version of this that has a Toggled version, but I am using my own.
|
||||
public static KeyState GetKeyState(IntPtr lParam) => (((ulong)lParam & 0x80000000) == 0 ? KeyState.Down : KeyState.Up);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user