forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MouseJump]Also simulate mouse input event (microsoft#24527)
* [MouseJump]Also simulate mouse input event * fix spellchecker
- Loading branch information
1 parent
b14a1f3
commit fef7b10
Showing
3 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/modules/MouseUtils/MouseJumpUI/Helpers/NativeMethods.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace MouseJumpUI.Helpers | ||
{ | ||
// Win32 functions required for temporary workaround for issue #1273 | ||
internal class NativeMethods | ||
{ | ||
[DllImport("user32.dll")] | ||
internal static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize); | ||
|
||
[DllImport("user32.dll")] | ||
internal static extern int GetSystemMetrics(SystemMetric smIndex); | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
public struct INPUT | ||
{ | ||
internal INPUTTYPE type; | ||
internal InputUnion data; | ||
|
||
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.Sequential)] | ||
internal struct MOUSEINPUT | ||
{ | ||
internal int dx; | ||
internal int dy; | ||
internal int mouseData; | ||
internal uint dwFlags; | ||
internal uint time; | ||
internal UIntPtr dwExtraInfo; | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
internal struct KEYBDINPUT | ||
{ | ||
internal short wVk; | ||
internal short wScan; | ||
internal uint dwFlags; | ||
internal int time; | ||
internal UIntPtr dwExtraInfo; | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
internal struct HARDWAREINPUT | ||
{ | ||
internal int uMsg; | ||
internal short wParamL; | ||
internal short wParamH; | ||
} | ||
|
||
internal enum INPUTTYPE : uint | ||
{ | ||
INPUT_MOUSE = 0, | ||
INPUT_KEYBOARD = 1, | ||
INPUT_HARDWARE = 2, | ||
} | ||
|
||
internal enum MOUSE_INPUT_FLAGS : uint | ||
{ | ||
MOUSEEVENTF_MOVE = 0x0001, | ||
MOUSEEVENTF_LEFTDOWN = 0x0002, | ||
MOUSEEVENTF_LEFTUP = 0x0004, | ||
MOUSEEVENTF_RIGHTDOWN = 0x0008, | ||
MOUSEEVENTF_RIGHTUP = 0x0010, | ||
MOUSEEVENTF_MIDDLEDOWN = 0x0020, | ||
MOUSEEVENTF_MIDDLEUP = 0x0040, | ||
MOUSEEVENTF_XDOWN = 0x0080, | ||
MOUSEEVENTF_XUP = 0x0100, | ||
MOUSEEVENTF_WHEEL = 0x0800, | ||
MOUSEEVENTF_HWHEEL = 0x1000, | ||
MOUSEEVENTF_MOVE_NOCOALESCE = 0x2000, | ||
MOUSEEVENTF_VIRTUALDESK = 0x4000, | ||
MOUSEEVENTF_ABSOLUTE = 0x8000, | ||
} | ||
|
||
internal enum SystemMetric | ||
{ | ||
SM_CXSCREEN = 0, | ||
SM_CYSCREEN = 1, | ||
} | ||
|
||
internal static int CalculateAbsoluteCoordinateX(int x) | ||
{ | ||
return (x * 65536) / GetSystemMetrics(SystemMetric.SM_CXSCREEN); | ||
} | ||
|
||
internal static int CalculateAbsoluteCoordinateY(int y) | ||
{ | ||
return (y * 65536) / GetSystemMetrics(SystemMetric.SM_CYSCREEN); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters