internal static bool SetForegroundWindow(IntPtr hWnd) { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { return(Win32Platform.SetForegroundWindow(hWnd)); } else if (Environment.OSVersion.Platform == PlatformID.Unix) { return(LinuxPlatform.SetForegroundWindow(hWnd)); } else { return(false); } }
internal static ushort GetAsyncKeyState(int key) { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { return(Win32Platform.GetAsyncKeyState(key)); } else if (Environment.OSVersion.Platform == PlatformID.Unix) { return(LinuxPlatform.GetAsyncKeyState(key)); } else { return(0); } }
internal static void BringToFront(IntPtr window) { try { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { Win32Platform.BringToFront(window); } else { LinuxPlatform.BringToFront(window); } } catch { } }
// A linux-version of WinUser.dll's GetAsyncKeyState() // Take the (Windows) Virtual Key Code, convert it to an X11 KeySym, then back to the X11 Keycode, then check if it's pressed. internal static ushort GetAsyncKeyState(int winkey) { try { int key = 0; int key2 = 0; bool pressed = false; bool pressed2 = false; // Convert Windows Virtual Key Code to an X11 Keysym. // Code elsewhere distills Left/Right modifier keys to Window's single keycode. Un-distill them here if (winkey == 0x10) { key = 0xFFE1; key2 = 0xFFE2; } // Any shift key else if (winkey == 0x11) { key = 0xFFE3; key2 = 0xFFE4; } // Any ctrl key else if (winkey == 0x12) { key = 0xFFE9; key2 = 0xFFEA; } // Any alt key else { key = LinuxPlatform.MapX11Key(winkey); } // Any other key, map the keycode to a keysym // Get physical keyboard state - every key being pressed is listed in the byte array var szKey = new byte[32]; int res = XQueryKeymap(Display, szKey); // Convert X11 Keysym to X11 Keycode int code = XKeysymToKeycode(Display, (int)key); // Check if keycode is included in the keyboard state. var r = szKey[code / 8]; var s = (1 << (code % 8)); pressed = Convert.ToBoolean(r & s); // Check the second modifier key if required if (key2 > 0) { int code2 = XKeysymToKeycode(Display, (int)key2); var r2 = szKey[code2 / 8]; var s2 = (1 << (code2 % 8)); pressed2 = Convert.ToBoolean(r2 & s2); } if (pressed || pressed2) { return((ushort)0xFF00); } else { return((ushort)0); } } catch { return((ushort)0); } }