mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 10:16:24 +02:00
113 lines
3.2 KiB
C#
113 lines
3.2 KiB
C#
// 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);
|
|
}
|
|
}
|
|
}
|