1

I was develop a application en C# WPF. In a new requirement, i need capture a Key combination, of letters and numbers only. For Example, AC, T2 etc...

I have implemented a lower level listener hook, but i don't have a idea for implement the logger for the combination.

Any ideas?

This is the hook:

 internal class InterceptKeys
{
    #region Delegates

    /// <summary>
    /// Delegate from keypress
    /// </summary>
    /// <param name="nCode">Code of Key</param>
    /// <param name="wParam">wParam</param>
    /// <param name="lParam">lParam</param>
    /// <returns>return next Call</returns>
    public delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);

    #endregion

    private const int WH_KEYBOARD_LL = 13;
    private const int WM_KEYDOWN = 0x0100;

    public static IntPtr SetHook(LowLevelKeyboardProc proc)
    {
        using (Process curProcess = Process.GetCurrentProcess())
        using (ProcessModule curModule = curProcess.MainModule)
        {
            return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
        }
    }

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern IntPtr SetWindowsHookEx(int idHook,
                                                  LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool UnhookWindowsHookEx(IntPtr hhk);

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
                                               IntPtr wParam, IntPtr lParam);

    [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern IntPtr GetModuleHandle(string lpModuleName);
}
  • Is [this](https://stackoverflow.com/questions/1361350/keyboard-shortcuts-in-wpf?rq=1) answer of any use to you? It might fit your use case – jrbeverly Jan 13 '17 at 00:26
  • It's not a command what I need. And only numbers and letrers. But thks i check that way. – user3582756 Jan 13 '17 at 00:52
  • Not logging, but I also use the Cheet.NET library for keyboard hooking http://jamiehumphries.github.io/Cheet.NET/ – kenny Jan 24 '18 at 14:25

0 Answers0