diff --git a/Assets/HOTK/Portal/DesktopPortalController.cs b/Assets/HOTK/Portal/DesktopPortalController.cs
index b40e3c1..b9cb442 100644
--- a/Assets/HOTK/Portal/DesktopPortalController.cs
+++ b/Assets/HOTK/Portal/DesktopPortalController.cs
@@ -376,7 +376,7 @@ private void AimAtApplication(HOTK_Overlay o, HOTK_TrackedDevice tracker, HOTK_O
_didHitOverlay = true;
if (SelectedWindowSettings.interactionMode == MouseInteractionMode.DirectInteraction ||
SelectedWindowSettings.interactionMode == MouseInteractionMode.WindowTop)
- Win32Stuff.BringWindowToTop(_selectedWindow);
+ Win32Stuff.SetForegroundWindow(_selectedWindow);
if (SelectedWindowSettings.interactionMode == MouseInteractionMode.DirectInteraction)
{
diff --git a/Assets/ScreenCapture/CursorInteraction.cs b/Assets/ScreenCapture/CursorInteraction.cs
index 87af745..c92ebdb 100644
--- a/Assets/ScreenCapture/CursorInteraction.cs
+++ b/Assets/ScreenCapture/CursorInteraction.cs
@@ -1,4 +1,5 @@
using System;
+using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
@@ -21,11 +22,33 @@ public class CursorInteraction
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern bool SendNotifyMessage(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam);
+ [return: MarshalAs(UnmanagedType.Bool)]
+ [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
+ static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
+
+
#pragma warning disable 649
- internal struct INPUT
+ #region SendInput Structs
+ [StructLayout(LayoutKind.Sequential)]
+ public struct INPUT
{
- public UInt32 Type;
- public MOUSEKEYBDHARDWAREINPUT Data;
+ internal InputType type;
+ internal InputUnion U;
+ internal static int Size
+ {
+ get { return Marshal.SizeOf(typeof(INPUT)); }
+ }
+ }
+
+ [StructLayout(LayoutKind.Explicit)]
+ internal struct InputUnion
+ {
+ [FieldOffset(0)]
+ internal MOUSEINPUT mi;
+ [FieldOffset(0)]
+ internal KEYBDINPUT ki;
+ [FieldOffset(0)]
+ internal HARDWAREINPUT hi;
}
[StructLayout(LayoutKind.Explicit)]
@@ -34,55 +57,948 @@ internal struct MOUSEKEYBDHARDWAREINPUT
[FieldOffset(0)]
public MOUSEINPUT Mouse;
}
-
+ [StructLayout(LayoutKind.Sequential)]
internal struct MOUSEINPUT
{
- public Int32 X;
- public Int32 Y;
- public UInt32 MouseData;
- public UInt32 Flags;
- public UInt32 Time;
- public IntPtr ExtraInfo;
+ internal int dx;
+ internal int dy;
+ internal int mouseData;
+ internal MOUSEEVENTF dwFlags;
+ internal uint time;
+ internal UIntPtr dwExtraInfo;
}
-
-#pragma warning restore 649
-
- // Click a foreground window
- /*public static void ClickOnPointAtCursor(IntPtr wndHandle, Point clientPoint)
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct KEYBDINPUT
{
- var oldPos = Cursor.Position;
-
- /// get screen coordinates
- ClientToScreen(wndHandle, ref clientPoint);
-
- /// set cursor on coords, and press mouse
- Cursor.Position = new Point(clientPoint.X, clientPoint.Y);
-
- var inputMouseDown = new INPUT();
- inputMouseDown.Type = 0; /// input type mouse
- inputMouseDown.Data.Mouse.Flags = 0x0002; /// left button down
-
- var inputMouseUp = new INPUT();
- inputMouseUp.Type = 0; /// input type mouse
- inputMouseUp.Data.Mouse.Flags = 0x0004; /// left button up
+ internal VirtualKeyShort wVk;
+ internal ScanCodeShort wScan;
+ internal KEYEVENTF dwFlags;
+ internal int time;
+ internal UIntPtr dwExtraInfo;
+ }
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct HARDWAREINPUT
+ {
+ internal int uMsg;
+ internal short wParamL;
+ internal short wParamH;
+ }
+ #endregion
+ #region Enums
+ internal enum InputType : uint
+ {
+ MOUSE = 0,
+ KEYBOARD = 1,
+ HARDWARE = 2
+ }
+ [Flags]
+ internal enum MOUSEEVENTF : uint
+ {
+ ABSOLUTE = 0x8000,
+ HWHEEL = 0x01000,
+ MOVE = 0x0001,
+ MOVE_NOCOALESCE = 0x2000,
+ LEFTDOWN = 0x0002,
+ LEFTUP = 0x0004,
+ RIGHTDOWN = 0x0008,
+ RIGHTUP = 0x0010,
+ MIDDLEDOWN = 0x0020,
+ MIDDLEUP = 0x0040,
+ VIRTUALDESK = 0x4000,
+ WHEEL = 0x0800,
+ XDOWN = 0x0080,
+ XUP = 0x0100
+ }
+ [Flags]
+ internal enum KEYEVENTF : uint
+ {
+ EXTENDEDKEY = 0x0001,
+ KEYUP = 0x0002,
+ SCANCODE = 0x0008,
+ UNICODE = 0x0004
+ }
- var inputs = new INPUT[] { inputMouseDown, inputMouseUp };
- SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
+ internal enum VirtualKeyShort : short
+ {
+ ///
+ ///Left mouse button
+ ///
+ LBUTTON = 0x01,
+ ///
+ ///Right mouse button
+ ///
+ RBUTTON = 0x02,
+ ///
+ ///Control-break processing
+ ///
+ CANCEL = 0x03,
+ ///
+ ///Middle mouse button (three-button mouse)
+ ///
+ MBUTTON = 0x04,
+ ///
+ ///Windows 2000/XP: X1 mouse button
+ ///
+ XBUTTON1 = 0x05,
+ ///
+ ///Windows 2000/XP: X2 mouse button
+ ///
+ XBUTTON2 = 0x06,
+ ///
+ ///BACKSPACE key
+ ///
+ BACK = 0x08,
+ ///
+ ///TAB key
+ ///
+ TAB = 0x09,
+ ///
+ ///CLEAR key
+ ///
+ CLEAR = 0x0C,
+ ///
+ ///ENTER key
+ ///
+ RETURN = 0x0D,
+ ///
+ ///SHIFT key
+ ///
+ SHIFT = 0x10,
+ ///
+ ///CTRL key
+ ///
+ CONTROL = 0x11,
+ ///
+ ///ALT key
+ ///
+ MENU = 0x12,
+ ///
+ ///PAUSE key
+ ///
+ PAUSE = 0x13,
+ ///
+ ///CAPS LOCK key
+ ///
+ CAPITAL = 0x14,
+ ///
+ ///Input Method Editor (IME) Kana mode
+ ///
+ KANA = 0x15,
+ ///
+ ///IME Hangul mode
+ ///
+ HANGUL = 0x15,
+ ///
+ ///IME Junja mode
+ ///
+ JUNJA = 0x17,
+ ///
+ ///IME final mode
+ ///
+ FINAL = 0x18,
+ ///
+ ///IME Hanja mode
+ ///
+ HANJA = 0x19,
+ ///
+ ///IME Kanji mode
+ ///
+ KANJI = 0x19,
+ ///
+ ///ESC key
+ ///
+ ESCAPE = 0x1B,
+ ///
+ ///IME convert
+ ///
+ CONVERT = 0x1C,
+ ///
+ ///IME nonconvert
+ ///
+ NONCONVERT = 0x1D,
+ ///
+ ///IME accept
+ ///
+ ACCEPT = 0x1E,
+ ///
+ ///IME mode change request
+ ///
+ MODECHANGE = 0x1F,
+ ///
+ ///SPACEBAR
+ ///
+ SPACE = 0x20,
+ ///
+ ///PAGE UP key
+ ///
+ PRIOR = 0x21,
+ ///
+ ///PAGE DOWN key
+ ///
+ NEXT = 0x22,
+ ///
+ ///END key
+ ///
+ END = 0x23,
+ ///
+ ///HOME key
+ ///
+ HOME = 0x24,
+ ///
+ ///LEFT ARROW key
+ ///
+ LEFT = 0x25,
+ ///
+ ///UP ARROW key
+ ///
+ UP = 0x26,
+ ///
+ ///RIGHT ARROW key
+ ///
+ RIGHT = 0x27,
+ ///
+ ///DOWN ARROW key
+ ///
+ DOWN = 0x28,
+ ///
+ ///SELECT key
+ ///
+ SELECT = 0x29,
+ ///
+ ///PRINT key
+ ///
+ PRINT = 0x2A,
+ ///
+ ///EXECUTE key
+ ///
+ EXECUTE = 0x2B,
+ ///
+ ///PRINT SCREEN key
+ ///
+ SNAPSHOT = 0x2C,
+ ///
+ ///INS key
+ ///
+ INSERT = 0x2D,
+ ///
+ ///DEL key
+ ///
+ DELETE = 0x2E,
+ ///
+ ///HELP key
+ ///
+ HELP = 0x2F,
+ ///
+ ///0 key
+ ///
+ KEY_0 = 0x30,
+ ///
+ ///1 key
+ ///
+ KEY_1 = 0x31,
+ ///
+ ///2 key
+ ///
+ KEY_2 = 0x32,
+ ///
+ ///3 key
+ ///
+ KEY_3 = 0x33,
+ ///
+ ///4 key
+ ///
+ KEY_4 = 0x34,
+ ///
+ ///5 key
+ ///
+ KEY_5 = 0x35,
+ ///
+ ///6 key
+ ///
+ KEY_6 = 0x36,
+ ///
+ ///7 key
+ ///
+ KEY_7 = 0x37,
+ ///
+ ///8 key
+ ///
+ KEY_8 = 0x38,
+ ///
+ ///9 key
+ ///
+ KEY_9 = 0x39,
+ ///
+ ///A key
+ ///
+ KEY_A = 0x41,
+ ///
+ ///B key
+ ///
+ KEY_B = 0x42,
+ ///
+ ///C key
+ ///
+ KEY_C = 0x43,
+ ///
+ ///D key
+ ///
+ KEY_D = 0x44,
+ ///
+ ///E key
+ ///
+ KEY_E = 0x45,
+ ///
+ ///F key
+ ///
+ KEY_F = 0x46,
+ ///
+ ///G key
+ ///
+ KEY_G = 0x47,
+ ///
+ ///H key
+ ///
+ KEY_H = 0x48,
+ ///
+ ///I key
+ ///
+ KEY_I = 0x49,
+ ///
+ ///J key
+ ///
+ KEY_J = 0x4A,
+ ///
+ ///K key
+ ///
+ KEY_K = 0x4B,
+ ///
+ ///L key
+ ///
+ KEY_L = 0x4C,
+ ///
+ ///M key
+ ///
+ KEY_M = 0x4D,
+ ///
+ ///N key
+ ///
+ KEY_N = 0x4E,
+ ///
+ ///O key
+ ///
+ KEY_O = 0x4F,
+ ///
+ ///P key
+ ///
+ KEY_P = 0x50,
+ ///
+ ///Q key
+ ///
+ KEY_Q = 0x51,
+ ///
+ ///R key
+ ///
+ KEY_R = 0x52,
+ ///
+ ///S key
+ ///
+ KEY_S = 0x53,
+ ///
+ ///T key
+ ///
+ KEY_T = 0x54,
+ ///
+ ///U key
+ ///
+ KEY_U = 0x55,
+ ///
+ ///V key
+ ///
+ KEY_V = 0x56,
+ ///
+ ///W key
+ ///
+ KEY_W = 0x57,
+ ///
+ ///X key
+ ///
+ KEY_X = 0x58,
+ ///
+ ///Y key
+ ///
+ KEY_Y = 0x59,
+ ///
+ ///Z key
+ ///
+ KEY_Z = 0x5A,
+ ///
+ ///Left Windows key (Microsoft Natural keyboard)
+ ///
+ LWIN = 0x5B,
+ ///
+ ///Right Windows key (Natural keyboard)
+ ///
+ RWIN = 0x5C,
+ ///
+ ///Applications key (Natural keyboard)
+ ///
+ APPS = 0x5D,
+ ///
+ ///Computer Sleep key
+ ///
+ SLEEP = 0x5F,
+ ///
+ ///Numeric keypad 0 key
+ ///
+ NUMPAD0 = 0x60,
+ ///
+ ///Numeric keypad 1 key
+ ///
+ NUMPAD1 = 0x61,
+ ///
+ ///Numeric keypad 2 key
+ ///
+ NUMPAD2 = 0x62,
+ ///
+ ///Numeric keypad 3 key
+ ///
+ NUMPAD3 = 0x63,
+ ///
+ ///Numeric keypad 4 key
+ ///
+ NUMPAD4 = 0x64,
+ ///
+ ///Numeric keypad 5 key
+ ///
+ NUMPAD5 = 0x65,
+ ///
+ ///Numeric keypad 6 key
+ ///
+ NUMPAD6 = 0x66,
+ ///
+ ///Numeric keypad 7 key
+ ///
+ NUMPAD7 = 0x67,
+ ///
+ ///Numeric keypad 8 key
+ ///
+ NUMPAD8 = 0x68,
+ ///
+ ///Numeric keypad 9 key
+ ///
+ NUMPAD9 = 0x69,
+ ///
+ ///Multiply key
+ ///
+ MULTIPLY = 0x6A,
+ ///
+ ///Add key
+ ///
+ ADD = 0x6B,
+ ///
+ ///Separator key
+ ///
+ SEPARATOR = 0x6C,
+ ///
+ ///Subtract key
+ ///
+ SUBTRACT = 0x6D,
+ ///
+ ///Decimal key
+ ///
+ DECIMAL = 0x6E,
+ ///
+ ///Divide key
+ ///
+ DIVIDE = 0x6F,
+ ///
+ ///F1 key
+ ///
+ F1 = 0x70,
+ ///
+ ///F2 key
+ ///
+ F2 = 0x71,
+ ///
+ ///F3 key
+ ///
+ F3 = 0x72,
+ ///
+ ///F4 key
+ ///
+ F4 = 0x73,
+ ///
+ ///F5 key
+ ///
+ F5 = 0x74,
+ ///
+ ///F6 key
+ ///
+ F6 = 0x75,
+ ///
+ ///F7 key
+ ///
+ F7 = 0x76,
+ ///
+ ///F8 key
+ ///
+ F8 = 0x77,
+ ///
+ ///F9 key
+ ///
+ F9 = 0x78,
+ ///
+ ///F10 key
+ ///
+ F10 = 0x79,
+ ///
+ ///F11 key
+ ///
+ F11 = 0x7A,
+ ///
+ ///F12 key
+ ///
+ F12 = 0x7B,
+ ///
+ ///F13 key
+ ///
+ F13 = 0x7C,
+ ///
+ ///F14 key
+ ///
+ F14 = 0x7D,
+ ///
+ ///F15 key
+ ///
+ F15 = 0x7E,
+ ///
+ ///F16 key
+ ///
+ F16 = 0x7F,
+ ///
+ ///F17 key
+ ///
+ F17 = 0x80,
+ ///
+ ///F18 key
+ ///
+ F18 = 0x81,
+ ///
+ ///F19 key
+ ///
+ F19 = 0x82,
+ ///
+ ///F20 key
+ ///
+ F20 = 0x83,
+ ///
+ ///F21 key
+ ///
+ F21 = 0x84,
+ ///
+ ///F22 key, (PPC only) Key used to lock device.
+ ///
+ F22 = 0x85,
+ ///
+ ///F23 key
+ ///
+ F23 = 0x86,
+ ///
+ ///F24 key
+ ///
+ F24 = 0x87,
+ ///
+ ///NUM LOCK key
+ ///
+ NUMLOCK = 0x90,
+ ///
+ ///SCROLL LOCK key
+ ///
+ SCROLL = 0x91,
+ ///
+ ///Left SHIFT key
+ ///
+ LSHIFT = 0xA0,
+ ///
+ ///Right SHIFT key
+ ///
+ RSHIFT = 0xA1,
+ ///
+ ///Left CONTROL key
+ ///
+ LCONTROL = 0xA2,
+ ///
+ ///Right CONTROL key
+ ///
+ RCONTROL = 0xA3,
+ ///
+ ///Left MENU key
+ ///
+ LMENU = 0xA4,
+ ///
+ ///Right MENU key
+ ///
+ RMENU = 0xA5,
+ ///
+ ///Windows 2000/XP: Browser Back key
+ ///
+ BROWSER_BACK = 0xA6,
+ ///
+ ///Windows 2000/XP: Browser Forward key
+ ///
+ BROWSER_FORWARD = 0xA7,
+ ///
+ ///Windows 2000/XP: Browser Refresh key
+ ///
+ BROWSER_REFRESH = 0xA8,
+ ///
+ ///Windows 2000/XP: Browser Stop key
+ ///
+ BROWSER_STOP = 0xA9,
+ ///
+ ///Windows 2000/XP: Browser Search key
+ ///
+ BROWSER_SEARCH = 0xAA,
+ ///
+ ///Windows 2000/XP: Browser Favorites key
+ ///
+ BROWSER_FAVORITES = 0xAB,
+ ///
+ ///Windows 2000/XP: Browser Start and Home key
+ ///
+ BROWSER_HOME = 0xAC,
+ ///
+ ///Windows 2000/XP: Volume Mute key
+ ///
+ VOLUME_MUTE = 0xAD,
+ ///
+ ///Windows 2000/XP: Volume Down key
+ ///
+ VOLUME_DOWN = 0xAE,
+ ///
+ ///Windows 2000/XP: Volume Up key
+ ///
+ VOLUME_UP = 0xAF,
+ ///
+ ///Windows 2000/XP: Next Track key
+ ///
+ MEDIA_NEXT_TRACK = 0xB0,
+ ///
+ ///Windows 2000/XP: Previous Track key
+ ///
+ MEDIA_PREV_TRACK = 0xB1,
+ ///
+ ///Windows 2000/XP: Stop Media key
+ ///
+ MEDIA_STOP = 0xB2,
+ ///
+ ///Windows 2000/XP: Play/Pause Media key
+ ///
+ MEDIA_PLAY_PAUSE = 0xB3,
+ ///
+ ///Windows 2000/XP: Start Mail key
+ ///
+ LAUNCH_MAIL = 0xB4,
+ ///
+ ///Windows 2000/XP: Select Media key
+ ///
+ LAUNCH_MEDIA_SELECT = 0xB5,
+ ///
+ ///Windows 2000/XP: Start Application 1 key
+ ///
+ LAUNCH_APP1 = 0xB6,
+ ///
+ ///Windows 2000/XP: Start Application 2 key
+ ///
+ LAUNCH_APP2 = 0xB7,
+ ///
+ ///Used for miscellaneous characters; it can vary by keyboard.
+ ///
+ OEM_1 = 0xBA,
+ ///
+ ///Windows 2000/XP: For any country/region, the '+' key
+ ///
+ OEM_PLUS = 0xBB,
+ ///
+ ///Windows 2000/XP: For any country/region, the ',' key
+ ///
+ OEM_COMMA = 0xBC,
+ ///
+ ///Windows 2000/XP: For any country/region, the '-' key
+ ///
+ OEM_MINUS = 0xBD,
+ ///
+ ///Windows 2000/XP: For any country/region, the '.' key
+ ///
+ OEM_PERIOD = 0xBE,
+ ///
+ ///Used for miscellaneous characters; it can vary by keyboard.
+ ///
+ OEM_2 = 0xBF,
+ ///
+ ///Used for miscellaneous characters; it can vary by keyboard.
+ ///
+ OEM_3 = 0xC0,
+ ///
+ ///Used for miscellaneous characters; it can vary by keyboard.
+ ///
+ OEM_4 = 0xDB,
+ ///
+ ///Used for miscellaneous characters; it can vary by keyboard.
+ ///
+ OEM_5 = 0xDC,
+ ///
+ ///Used for miscellaneous characters; it can vary by keyboard.
+ ///
+ OEM_6 = 0xDD,
+ ///
+ ///Used for miscellaneous characters; it can vary by keyboard.
+ ///
+ OEM_7 = 0xDE,
+ ///
+ ///Used for miscellaneous characters; it can vary by keyboard.
+ ///
+ OEM_8 = 0xDF,
+ ///
+ ///Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard
+ ///
+ OEM_102 = 0xE2,
+ ///
+ ///Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key
+ ///
+ PROCESSKEY = 0xE5,
+ ///
+ ///Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes.
+ ///The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information,
+ ///see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP
+ ///
+ PACKET = 0xE7,
+ ///
+ ///Attn key
+ ///
+ ATTN = 0xF6,
+ ///
+ ///CrSel key
+ ///
+ CRSEL = 0xF7,
+ ///
+ ///ExSel key
+ ///
+ EXSEL = 0xF8,
+ ///
+ ///Erase EOF key
+ ///
+ EREOF = 0xF9,
+ ///
+ ///Play key
+ ///
+ PLAY = 0xFA,
+ ///
+ ///Zoom key
+ ///
+ ZOOM = 0xFB,
+ ///
+ ///Reserved
+ ///
+ NONAME = 0xFC,
+ ///
+ ///PA1 key
+ ///
+ PA1 = 0xFD,
+ ///
+ ///Clear key
+ ///
+ OEM_CLEAR = 0xFE
+ }
+ internal enum ScanCodeShort : short
+ {
+ LBUTTON = 0,
+ RBUTTON = 0,
+ CANCEL = 70,
+ MBUTTON = 0,
+ XBUTTON1 = 0,
+ XBUTTON2 = 0,
+ BACK = 14,
+ TAB = 15,
+ CLEAR = 76,
+ RETURN = 28,
+ SHIFT = 42,
+ CONTROL = 29,
+ MENU = 56,
+ PAUSE = 0,
+ CAPITAL = 58,
+ KANA = 0,
+ HANGUL = 0,
+ JUNJA = 0,
+ FINAL = 0,
+ HANJA = 0,
+ KANJI = 0,
+ ESCAPE = 1,
+ CONVERT = 0,
+ NONCONVERT = 0,
+ ACCEPT = 0,
+ MODECHANGE = 0,
+ SPACE = 57,
+ PRIOR = 73,
+ NEXT = 81,
+ END = 79,
+ HOME = 71,
+ LEFT = 75,
+ UP = 72,
+ RIGHT = 77,
+ DOWN = 80,
+ SELECT = 0,
+ PRINT = 0,
+ EXECUTE = 0,
+ SNAPSHOT = 84,
+ INSERT = 82,
+ DELETE = 83,
+ HELP = 99,
+ KEY_0 = 11,
+ KEY_1 = 2,
+ KEY_2 = 3,
+ KEY_3 = 4,
+ KEY_4 = 5,
+ KEY_5 = 6,
+ KEY_6 = 7,
+ KEY_7 = 8,
+ KEY_8 = 9,
+ KEY_9 = 10,
+ KEY_A = 30,
+ KEY_B = 48,
+ KEY_C = 46,
+ KEY_D = 32,
+ KEY_E = 18,
+ KEY_F = 33,
+ KEY_G = 34,
+ KEY_H = 35,
+ KEY_I = 23,
+ KEY_J = 36,
+ KEY_K = 37,
+ KEY_L = 38,
+ KEY_M = 50,
+ KEY_N = 49,
+ KEY_O = 24,
+ KEY_P = 25,
+ KEY_Q = 16,
+ KEY_R = 19,
+ KEY_S = 31,
+ KEY_T = 20,
+ KEY_U = 22,
+ KEY_V = 47,
+ KEY_W = 17,
+ KEY_X = 45,
+ KEY_Y = 21,
+ KEY_Z = 44,
+ LWIN = 91,
+ RWIN = 92,
+ APPS = 93,
+ SLEEP = 95,
+ NUMPAD0 = 82,
+ NUMPAD1 = 79,
+ NUMPAD2 = 80,
+ NUMPAD3 = 81,
+ NUMPAD4 = 75,
+ NUMPAD5 = 76,
+ NUMPAD6 = 77,
+ NUMPAD7 = 71,
+ NUMPAD8 = 72,
+ NUMPAD9 = 73,
+ MULTIPLY = 55,
+ ADD = 78,
+ SEPARATOR = 0,
+ SUBTRACT = 74,
+ DECIMAL = 83,
+ DIVIDE = 53,
+ F1 = 59,
+ F2 = 60,
+ F3 = 61,
+ F4 = 62,
+ F5 = 63,
+ F6 = 64,
+ F7 = 65,
+ F8 = 66,
+ F9 = 67,
+ F10 = 68,
+ F11 = 87,
+ F12 = 88,
+ F13 = 100,
+ F14 = 101,
+ F15 = 102,
+ F16 = 103,
+ F17 = 104,
+ F18 = 105,
+ F19 = 106,
+ F20 = 107,
+ F21 = 108,
+ F22 = 109,
+ F23 = 110,
+ F24 = 118,
+ NUMLOCK = 69,
+ SCROLL = 70,
+ LSHIFT = 42,
+ RSHIFT = 54,
+ LCONTROL = 29,
+ RCONTROL = 29,
+ LMENU = 56,
+ RMENU = 56,
+ BROWSER_BACK = 106,
+ BROWSER_FORWARD = 105,
+ BROWSER_REFRESH = 103,
+ BROWSER_STOP = 104,
+ BROWSER_SEARCH = 101,
+ BROWSER_FAVORITES = 102,
+ BROWSER_HOME = 50,
+ VOLUME_MUTE = 32,
+ VOLUME_DOWN = 46,
+ VOLUME_UP = 48,
+ MEDIA_NEXT_TRACK = 25,
+ MEDIA_PREV_TRACK = 16,
+ MEDIA_STOP = 36,
+ MEDIA_PLAY_PAUSE = 34,
+ LAUNCH_MAIL = 108,
+ LAUNCH_MEDIA_SELECT = 109,
+ LAUNCH_APP1 = 107,
+ LAUNCH_APP2 = 33,
+ OEM_1 = 39,
+ OEM_PLUS = 13,
+ OEM_COMMA = 51,
+ OEM_MINUS = 12,
+ OEM_PERIOD = 52,
+ OEM_2 = 53,
+ OEM_3 = 41,
+ OEM_4 = 26,
+ OEM_5 = 43,
+ OEM_6 = 27,
+ OEM_7 = 40,
+ OEM_8 = 0,
+ OEM_102 = 86,
+ PROCESSKEY = 0,
+ PACKET = 0,
+ ATTN = 0,
+ CRSEL = 0,
+ EXSEL = 0,
+ EREOF = 93,
+ PLAY = 0,
+ ZOOM = 98,
+ NONAME = 0,
+ PA1 = 0,
+ OEM_CLEAR = 0,
+ }
+ #endregion
- /// return mouse
- //Cursor.Position = oldPos;
- var oldPos = Cursor.Position;
- IntPtr lParam = (IntPtr)((clientPoint.Y << 16) | clientPoint.X);
- IntPtr lParam2 = (IntPtr)((clientPoint.Y << 16) | clientPoint.X - 1);
- IntPtr wParam = IntPtr.Zero;
- ClientToScreen(wndHandle, ref clientPoint);
- Cursor.Position = new Point(clientPoint.X, clientPoint.Y);
- SendMessage(wndHandle, (uint)MouseEvents.WM_MOUSEMOVE, wParam, lParam2);
- SendMessage(wndHandle, (uint)MouseEvents.WM_MOUSEMOVE, wParam, lParam);
- //SendMessage(wndHandle, (uint) MouseEvents.WM_LBUTTONDOWN, wParam, lParam);
- //SendMessage(wndHandle, (uint) MouseEvents.WM_LBUTTONUP, wParam, lParam);
- Cursor.Position = oldPos;
- }*/
+#pragma warning restore 649
+
+ public static void PostMessageSafe(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
+ {
+ bool returnValue = PostMessage(hWnd, msg, wParam, lParam);
+ if (!returnValue)
+ {
+ // An error occured
+ throw new Win32Exception(Marshal.GetLastWin32Error());
+ }
+ }
private static bool _clicking;
@@ -93,31 +1009,35 @@ public static void ClickOnPointAtCursor(IntPtr wndHandle, SimulationMode mode =
var clientPoint = new Point(Cursor.Position.X, Cursor.Position.Y);
ScreenToClient(wndHandle, ref clientPoint);
IntPtr lParam = (IntPtr)((clientPoint.Y << 16) | clientPoint.X);
+ INPUT[] pInputs;
// Click Mouse
switch (mode)
{
- case SimulationMode.LeftClick:
- SendNotifyMessage(wndHandle, (uint)MouseEvents.WM_LBUTTONDOWN, (UIntPtr)1, lParam);
- SendNotifyMessage(wndHandle, (uint)MouseEvents.WM_LBUTTONUP, UIntPtr.Zero, lParam);
- break;
case SimulationMode.RightClick:
- SendNotifyMessage(wndHandle, (uint)MouseEvents.WM_RBUTTONDOWN, (UIntPtr)2, lParam);
- SendNotifyMessage(wndHandle, (uint)MouseEvents.WM_RBUTTONUP, UIntPtr.Zero, lParam);
+ pInputs = new[]
+ {
+ new INPUT() { type = InputType.MOUSE, U = new InputUnion() { mi = new MOUSEINPUT() { dwFlags = MOUSEEVENTF.RIGHTDOWN, } } },
+ new INPUT() { type = InputType.MOUSE, U = new InputUnion() { mi = new MOUSEINPUT() { dwFlags = MOUSEEVENTF.RIGHTUP, } } } };
break;
+ case SimulationMode.LeftClick:
case SimulationMode.DoubleClick:
- SendNotifyMessage(wndHandle, (uint)MouseEvents.WM_LBUTTONDBLCLK, (UIntPtr)1, lParam);
- SendNotifyMessage(wndHandle, (uint)MouseEvents.WM_LBUTTONUP, UIntPtr.Zero, lParam);
+ pInputs = new []
+ {
+ new INPUT() { type = InputType.MOUSE, U = new InputUnion() { mi = new MOUSEINPUT() { dwFlags = MOUSEEVENTF.LEFTDOWN, } } },
+ new INPUT() { type = InputType.MOUSE, U = new InputUnion() { mi = new MOUSEINPUT() { dwFlags = MOUSEEVENTF.LEFTUP, } } }
+ };
break;
default:
throw new ArgumentOutOfRangeException("mode", mode, null);
}
+ if (pInputs.Length > 0)
+ SendInput((uint)pInputs.Length, pInputs, INPUT.Size);
_clicking = true;
}
// Click on a window even if it's in the background
public static void ClickOnPoint(IntPtr wndHandle, Point clientPoint, SimulationMode mode = SimulationMode.LeftClick)
{
- //UnityEngine.Debug.Log(clientPoint.X + " / " + clientPoint.Y);
var oldPos = Cursor.Position;
IntPtr lParam = (IntPtr) ((clientPoint.Y << 16) | clientPoint.X);
ClientToScreen(wndHandle, ref clientPoint);
diff --git a/Assets/ScreenCapture/Win32Stuff.cs b/Assets/ScreenCapture/Win32Stuff.cs
index f2e9817..8e2f638 100644
--- a/Assets/ScreenCapture/Win32Stuff.cs
+++ b/Assets/ScreenCapture/Win32Stuff.cs
@@ -115,6 +115,11 @@ public WINDOWINFO(Boolean? filler) : this() // Allows automatic initialization
[DllImport("user32.dll", SetLastError = true)]
public static extern bool BringWindowToTop(IntPtr hWnd);
+ [DllImport("user32.dll")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool SetForegroundWindow(IntPtr hWnd);
+
+
///
/// Determines the visibility state of the specified window.
///
diff --git a/Library/CrashedAssetImports.txt b/Library/CrashedAssetImports.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/Library/EditorUserBuildSettings.asset b/Library/EditorUserBuildSettings.asset
index 1abfed9..c4b977f 100644
Binary files a/Library/EditorUserBuildSettings.asset and b/Library/EditorUserBuildSettings.asset differ
diff --git a/Library/ScriptAssemblies/Assembly-CSharp-Editor.dll b/Library/ScriptAssemblies/Assembly-CSharp-Editor.dll
index d38fb8f..2e620aa 100644
Binary files a/Library/ScriptAssemblies/Assembly-CSharp-Editor.dll and b/Library/ScriptAssemblies/Assembly-CSharp-Editor.dll differ
diff --git a/Library/ScriptAssemblies/Assembly-CSharp-Editor.dll.mdb b/Library/ScriptAssemblies/Assembly-CSharp-Editor.dll.mdb
index 679a1fe..b3a4440 100644
Binary files a/Library/ScriptAssemblies/Assembly-CSharp-Editor.dll.mdb and b/Library/ScriptAssemblies/Assembly-CSharp-Editor.dll.mdb differ
diff --git a/Library/ScriptAssemblies/Assembly-CSharp-firstpass.dll b/Library/ScriptAssemblies/Assembly-CSharp-firstpass.dll
index 4c2889e..0c9a7b4 100644
Binary files a/Library/ScriptAssemblies/Assembly-CSharp-firstpass.dll and b/Library/ScriptAssemblies/Assembly-CSharp-firstpass.dll differ
diff --git a/Library/ScriptAssemblies/Assembly-CSharp-firstpass.dll.mdb b/Library/ScriptAssemblies/Assembly-CSharp-firstpass.dll.mdb
index d622164..59dd839 100644
Binary files a/Library/ScriptAssemblies/Assembly-CSharp-firstpass.dll.mdb and b/Library/ScriptAssemblies/Assembly-CSharp-firstpass.dll.mdb differ
diff --git a/Library/ScriptAssemblies/Assembly-CSharp.dll b/Library/ScriptAssemblies/Assembly-CSharp.dll
index 8d5dd9e..6e95566 100644
Binary files a/Library/ScriptAssemblies/Assembly-CSharp.dll and b/Library/ScriptAssemblies/Assembly-CSharp.dll differ
diff --git a/Library/ScriptAssemblies/Assembly-CSharp.dll.mdb b/Library/ScriptAssemblies/Assembly-CSharp.dll.mdb
index 6966f91..4bbbf43 100644
Binary files a/Library/ScriptAssemblies/Assembly-CSharp.dll.mdb and b/Library/ScriptAssemblies/Assembly-CSharp.dll.mdb differ
diff --git a/Library/assetDatabase3 b/Library/assetDatabase3
index 9533835..5f22c16 100644
Binary files a/Library/assetDatabase3 and b/Library/assetDatabase3 differ
diff --git a/Library/metadata/00/00000000000000004000000000000000 b/Library/metadata/00/00000000000000004000000000000000
index 455a138..e2af35e 100644
Binary files a/Library/metadata/00/00000000000000004000000000000000 and b/Library/metadata/00/00000000000000004000000000000000 differ
diff --git a/Library/metadata/00/00000000000000006100000000000000 b/Library/metadata/00/00000000000000006100000000000000
index 12e3f13..70c213c 100644
Binary files a/Library/metadata/00/00000000000000006100000000000000 and b/Library/metadata/00/00000000000000006100000000000000 differ
diff --git a/Library/metadata/48/48b5bcc676d3b6b48aa4f2d01cb6b7e0 b/Library/metadata/48/48b5bcc676d3b6b48aa4f2d01cb6b7e0
index 17f17f2..5217c81 100644
Binary files a/Library/metadata/48/48b5bcc676d3b6b48aa4f2d01cb6b7e0 and b/Library/metadata/48/48b5bcc676d3b6b48aa4f2d01cb6b7e0 differ
diff --git a/Library/metadata/6d/6d0b92c9bbe2a2644ac17d7fe3dfdd1f b/Library/metadata/6d/6d0b92c9bbe2a2644ac17d7fe3dfdd1f
index 84d645a..1367095 100644
Binary files a/Library/metadata/6d/6d0b92c9bbe2a2644ac17d7fe3dfdd1f and b/Library/metadata/6d/6d0b92c9bbe2a2644ac17d7fe3dfdd1f differ
diff --git a/Library/metadata/88/88700c9971834e34880595ae46852719 b/Library/metadata/88/88700c9971834e34880595ae46852719
index 4ebcd7c..d82b2b5 100644
Binary files a/Library/metadata/88/88700c9971834e34880595ae46852719 and b/Library/metadata/88/88700c9971834e34880595ae46852719 differ