private void SyncronizeKeyStates(UtilInterop.WindowMessage action, LowLevelKeyboardInput input) { for (int i = 0; i < _keyStates.Count; i++) { _keyStates.Set(i, (UInt16)UtilInterop.GetKeyState(i) >> 15 == 1 ? true : false); } _keyStates.Set((int)input.VirtualKeyCode, (action == UtilInterop.WindowMessage.WM_KEYDOWN || action == UtilInterop.WindowMessage.WM_SYSKEYDOWN) ? true : false); }
public static bool IsDesktopActive() { var gta = UtilInterop.FindWindow(null, "GTA:SA:MP"); if (gta != IntPtr.Zero) { return(gta != UtilInterop.GetForegroundWindow()); } return(false); }
private void ModuleWaitProcedure() { while (_moduleWaitRunning) { Thread.Sleep(TimeSpan.FromMilliseconds(50.0)); if (_processWatcher.WatchedProcess != null) { try { var gotModule = false; var moduleCollection = _processWatcher.WatchedProcess.Modules; foreach (ProcessModule item in moduleCollection) { if (item.ModuleName == "samp.dll" && UtilInterop.FindWindow(null, "GTA:SA:MP") != IntPtr.Zero) { InitializeAPI(); foreach (var component in _components) { component.ProcessStarted(); } _moduleWaitRunning = false; _gameRunning = true; gotModule = true; break; } } if (!gotModule) { _processWatcher.WatchedProcess.Refresh(); Thread.Sleep(500); } } catch (System.ComponentModel.Win32Exception) { } } else { _moduleWaitRunning = false; } } }
private void HookMessageProcedure() { #pragma warning disable CS0618 // Type or member is obsolete _threadId = (uint)AppDomain.GetCurrentThreadId(); #pragma warning restore CS0618 // Type or member is obsolete _keyboardHookProcedure = new HookProcedure(LowLevelKeyboardProcedure); _keyboardHookHandle = SetWindowsHookEx(HookType.WH_KEYBOARD_LL, _keyboardHookProcedure, UtilInterop.GetModuleHandle(null), 0); var message = new MSG(); while (_keyboardHookRunning) { var result = GetMessage(out message, IntPtr.Zero, 0, 0); if (result == -1) { break; } TranslateMessage(ref message); if (message.message == (int)UtilInterop.WindowMessage.WM_QUIT) { break; } } UnhookWindowsHookEx(_keyboardHookHandle); _keyboardHookHandle = IntPtr.Zero; }