-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathNative.cs
86 lines (76 loc) · 3.44 KB
/
Native.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace ClickPaste
{
class Native
{
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetProcessDPIAware();
[DllImport("user32.dll")]
public static extern bool SetSystemCursor(IntPtr hcur, uint id);
[DllImport("user32.dll")]
public static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern Int32 SystemParametersInfo(UInt32 uiAction, UInt32
uiParam, String pvParam, UInt32 fWinIni);
[DllImport("user32.dll")]
public static extern IntPtr CopyIcon(IntPtr pcur);
public static uint CROSS = 32515;
public static uint NORMAL = 32512;
public static uint IBEAM = 32513;
public static uint HAND = 32649;
[DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(int x, int y);
[DllImport("user32.dll")]
public static extern uint GetKeyboardLayoutList(int nBuff, [Out] IntPtr[] lpList);
[DllImport("user32.dll")]
public static extern IntPtr LoadKeyboardLayout(string pwszKLID, uint Flags);
[DllImport("user32.dll")]
public static extern bool GetKeyboardLayoutName([Out] StringBuilder pwszKLID);
[DllImport("user32.dll")]
public static extern IntPtr GetKeyboardLayout(uint idThread);
private const int KEY_PRESSED = 0x8000;
private const int VK_SHIFT = 0x10;
private const int VK_CONTROL = 0x11;
private const int VK_MENU = 0x12;
private const int VK_LWIN = 0x5B;
private const int VK_RWIN = 0x5C;
[DllImport("USER32.dll")]
static extern short GetKeyState(int nVirtKey);
public static bool IsModifierKeyPressed()
{
return
Convert.ToBoolean(GetKeyState(VK_SHIFT) & KEY_PRESSED) ||
Convert.ToBoolean(GetKeyState(VK_CONTROL) & KEY_PRESSED) ||
Convert.ToBoolean(GetKeyState(VK_MENU) & KEY_PRESSED) ||
Convert.ToBoolean(GetKeyState(VK_LWIN) & KEY_PRESSED) ||
Convert.ToBoolean(GetKeyState(VK_RWIN) & KEY_PRESSED);
}
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern IntPtr SetForegroundWindow(IntPtr hwnd);
[DllImport("user32.dll")]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
[DllImport("user32.dll")]
public static extern int ActivateKeyboardLayout(int HKL, int flags);
private static uint WM_INPUTLANGCHANGEREQUEST = 0x0050;
private static int HWND_BROADCAST = 0xffff;
private static uint KLF_ACTIVATE = 1;
[DllImport("user32.dll")]
public static extern void GetWindowText(IntPtr hWnd, StringBuilder lpString, Int32 nMaxCount);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int GetWindowTextLength(IntPtr hWnd);
public static string GetText(IntPtr hwnd)
{
int length = GetWindowTextLength(hwnd);
StringBuilder sb = new StringBuilder(length + 1);
GetWindowText(hwnd, sb, sb.Capacity);
return sb.ToString();
}
}
}