private HotkeysManager() { var keyboardHook = new LowLevelKeyboardHook(true); var mouseHook = new LowLevelMouseHook(true); _hotkeys = new Dictionary <string, HotkeyCommand>(); foreach (var settings in Properties.Hotkeys.Default.Properties.Cast <SettingsProperty>()) { if (!(Properties.Hotkeys.Default[settings.Name] is VirtualKeyCode keyCode)) { continue; } _hotkeys.Add(settings.Name, new HotkeyCommand { KeyCode = keyCode }); Logger.Get.Info($"Added hotkey {keyCode} for action {settings.Name}"); } Properties.Hotkeys.Default.PropertyChanged += OnSettingsPropertyChanged; keyboardHook.OnKeyboardEvent += OnKeyboardEvent; keyboardHook.InstallHook(); mouseHook.OnMouseEvent += MouseHook_OnMouseEvent; mouseHook.InstallHook(); Messenger.Default.Register <GameActiveStatusChanged>(this, msg => { mouseHook.CaptureMouseMove = msg.IsInForeground; }); }
public SettingsViewModell() : base("Settings") { SetupCombinations(); inputManager.OnKeyboardEvent += InputManager_OnKeyboardEvent; keyboardHook.OnKeyboardEvent += KeyboardHook_OnKeyboardEvent; inputManager.Initialize(); keyboardHook.InstallHook(); }
public static void Main(string[] args) { LowLevelKeyboardHook kbdHook = new LowLevelKeyboardHook(); LowLevelMouseHook mouseHook = new LowLevelMouseHook(); kbdHook.OnKeyboardEvent += KbdHook_OnKeyboardEvent; mouseHook.OnMouseEvent += MouseHook_OnMouseEvent; kbdHook.InstallHook(); mouseHook.InstallHook(); while (true) { Thread.Sleep(1); } }
static void Main(string[] args) { TestFilter(); return; // creates a new instance to capture inputs // also provides IsPressed, WasPressed and GetState methods var inputManager = new InputManager(); // you may not need those when you use InputManager var keyboardHook = new LowLevelKeyboardHook(); var mouseHook = new LowLevelMouseHook(); // subscribe to the events offered by InputManager inputManager.OnKeyboardEvent += InputManager_OnKeyboardEvent; inputManager.OnMouseEvent += InputManager_OnMouseEvent; // same events as above (in case you only need a specific hook and less functionality) keyboardHook.OnKeyboardEvent += KeyboardHook_OnKeyboardEvent; mouseHook.OnMouseEvent += MouseHook_OnMouseEvent; // we need to initialize our classes before they fire events and are completely usable inputManager.Initialize(); keyboardHook.InstallHook(); mouseHook.InstallHook(); // registers an event (callback) which gets fired whenever the key changes it's state // be sure to use this method after the InputManager is initialized inputManager.RegisterEvent(VirtualKeyCode.Lbutton, InputManager_KeyStateChanged); Console.WriteLine("Waiting for up arrow key to exit!"); // This method will block the current thread until the up arrow key changes it's state to Down // There is no performance penalty (spinning loop waiting for this) inputManager.WaitForEvent(VirtualKeyCode.Up, KeyState.Down); // be sure to dispose instances you dont use anymore // not doing so may block windows input and let inputs appear delayed or lagging // these classes try dispose itself when an unhandled exception occurs or the process exits mouseHook.Dispose(); keyboardHook.Dispose(); inputManager.Dispose(); }
//The Core off applications is here #region SetUp/SetDown/CheckUps/Updates private static void SetUp() { Console.CursorVisible = false; Console.Title = "Senac Clicker GameJam"; GetData(); SetUpVars(); // Disable the Console Edit mode, in way to never lock the main thread during execution due to selections on the window. DisableQuickEdit(); // Initialize Hookers who deal with all the inputs after now. KeyboardHook = new LowLevelKeyboardHook(); MouseHook = new LowLevelMouseHook(); // Defines actions to events. KeyboardHook.OnKeyboardEvent += KeyboardHook_OnKeyboardEvent; MouseHook.OnMouseEvent += MouseHook_OnMouseEvent; // Attach the hookers into main thread. KeyboardHook.InstallHook(); MouseHook.InstallHook(); }
private void Initialize(bool captureMouseMove, bool clearInjectedFlag) { // initialize vars lockObject = new object(); mapKeyState = new Dictionary <VirtualKeyCode, KeyState>(); foreach (var pair in KeyCodeConverter.EnumerateVirtualKeyCodes()) { mapKeyState.Add(pair.Key, KeyState.None); } singleKeyCallback = new Dictionary <VirtualKeyCode, List <KeyStateChangedCallback> >(); // initialize hooks keyboardHook = new LowLevelKeyboardHook(clearInjectedFlag); mouseHook = new LowLevelMouseHook(captureMouseMove, clearInjectedFlag); keyboardHook.OnKeyboardEvent += KeyboardHook_OnKeyboardEvent; mouseHook.OnMouseEvent += MouseHook_OnMouseEvent; keyboardHook.InstallHook(); mouseHook.InstallHook(); }