检测键盘输入后,窗口识别的关键

Detect keyboard input after windows recognition of the key

本文关键字:识别 窗口 键盘 输入 检测      更新时间:2023-10-16

我正在构建一个程序,它将在屏幕上打印出按下的按钮的值。我需要它的工作也当程序的窗口不活跃。我尝试使用GetAsyncKeyState(int),它工作得很好。然而,我可以将某些字符串附加到键上,但它不适用于所有类型的键盘(例如,在英语键盘上,shift+2是@,而在我的键盘上则不是)。我如何检测由Windows完成的键输入的后处理(在记事本中书写时在屏幕上打印的字符)?

尝试OemKeyScan函数。对于你的,你应该有扫描码(例如,"2"键有一个给定的扫描码,它总是相同的,取决于键盘上的位置,例如17的"2"键):

    int whichscancode= 17;
    if (key_with_shift)
        whichscancode|= (1<<16);  // shifted values with 1<<16
    for (i=0; i<256; i++) {
            int scan= ::OemKeyScan(i);  // try all characters for a matching scancode
            if (scan==whichscancode) {
                // i here is the ascii code of the key on that position
                printf("on that scancode is character %cn", (char)i);
            }
    }