简体   繁体   English

如何在SendInput中使用扩展的扫描代码

[英]How to use extended scancodes in SendInput

To emulate some keys I have to send there scancodes, to do this I use SendInput() function from WinAPI and it's work fine in most cases, but how to use it for sending scancodes for such keys as "Pause"? 为了模拟某些键,我必须将扫描码发送到那里,为此,我使用WinAPI中的SendInput()函数,并且在大多数情况下都可以正常工作,但是如何使用它为诸如“ Pause”之类的键发送扫描码? This key generates 6 byte scancode (E1 1D 45 E1 9D C5), as scancode in KEYBDINPUT structer has WORD type, ie allows to use scancodes up to 2 bytes only. 该密钥生成6字节的扫描码(E1 1D 45 E1 9D C5),因为KEYBDINPUT构造函数中的扫描码为WORD类型,即,最多只能使用2个字节的扫描码。 I tried 1D45 scancode and 9DC5 with KEYEVENTF_EXTENDEDKEY flag, suggesting that it apply E0\\E1 code depending on content. 我使用KEYEVENTF_EXTENDEDKEY标志尝试了1D45扫描代码和9DC5,建议它根据内容应用E0 \\ E1代码。 I also tried to send sequences of six 1 byte commands. 我还尝试发送六个六个1字节命令的序列。 But all that doesn't work. 但是,所有这些都不起作用。

I found the answer. 我找到了答案。 You have to send two inputs into your array for SendInput. 您必须将两个输入发送到数组中以进行SendInput。 The first entry will be 0xE0, and the second-entry will be your scancode. 第一个条目将是0xE0,第二个条目将是您的扫描代码。

I actually found the solution here, embedded in the graphic: https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-6.0/aa299374(v=vs.60) 我实际上在这里找到了解决方案,该解决方案嵌入在图形中: https : //docs.microsoft.com/zh-cn/previous-versions/visualstudio/visual-studio-6.0/aa299374(v=vs.60)

See code. 参见代码。 It's C#, but you'll get the idea. 它是C#,但您会明白的。

        inputs = new[]
        {
            new WinAPI.INPUT
            {
                type = WinAPI.INPUT_KEYBOARD,

                u = new WinAPI.InputUnion
                {
                    ki = new WinAPI.KEYBDINPUT()
                    {
                        wScan = (ushort) 0xe0,
                        wVk = (ushort) 0,
                        dwFlags = (ushort) dwFlags,
                        dwExtraInfo = WinAPI.GetMessageExtraInfo()
                    }
                }
            },
            new WinAPI.INPUT
            {
                type = WinAPI.INPUT_KEYBOARD,

                u = new WinAPI.InputUnion
                {
                    ki = new WinAPI.KEYBDINPUT()
                    {
                        wScan = (ushort) tscancode,
                        wVk = (ushort) tvk,
                        dwFlags = (ushort) dwFlags,
                        dwExtraInfo = WinAPI.GetMessageExtraInfo()
                    }
                }
            }
        };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM