1

ユーザーが別のアプリから押したキーを取得しようとしていますが、取得できるのは、キーボードの状態 (大文字/小文字/シフトが押された) なしで押されたキーの場所だけであり、実際のキーを取得したい

私のコード:

   private const int WH_KEYBOARD_LL = 13;
    private const int WM_KEYDOWN = 0x0100;
    private static LowLevelKeyboardProc _proc = HookCallback;
    private static IntPtr _hookID = IntPtr.Zero;
    private static int enteredChar;
    public static int EnteredChar
    {
        get { return enteredChar; }
    }
    public static void start()
    {
        _hookID = SetHook(_proc);
        Application.Run();

        UnhookWindowsHookEx(_hookID);
    }

    private 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);
        }
    }

    private delegate IntPtr LowLevelKeyboardProc(
        int nCode, IntPtr wParam, IntPtr lParam);

    private static IntPtr HookCallback(
        int nCode, IntPtr wParam, IntPtr lParam)
    {
        if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
        {
            //  char letter=(char) Marshal.ReadByte(lParam);
           enteredChar = Marshal.ReadInt32(lParam);
              Console.WriteLine((Keys)enteredChar);

        }

        return CallNextHookEx(_hookID, nCode, wParam, lParam);

    }
    public static int returnKey()
    {
        return enteredChar;
    }
4

0 に答える 0