gpt4 book ai didi

winapi - 键盘的 SendInput() - 只有小写

转载 作者:行者123 更新时间:2023-12-04 14:31:56 24 4
gpt4 key购买 nike

我有以下代码:

INPUT Input = { 0 };
Input.type = INPUT_KEYBOARD;
Input.mi.dwFlags = KEYEVENTF_EXTENDEDKEY;
Input.ki.wVk = 'A'; // tried 0x41, ( UCHAR )VkKeyScan( 'A' )
SendInput( 1, &Input, sizeof( INPUT ) );

但它只生成我'a'。如何强制它也生成大写?

谢谢。

最佳答案

编辑:根据评论中的罗德里戈回答进行了一些修改。

INPUT Input = { 0 };
// shift key down
Input.type = INPUT_KEYBOARD;
Input.ki.wVk = VK_LSHIFT;
SendInput( 1, &Input, sizeof( INPUT ) );

// 'a' key down
Input.type = INPUT_KEYBOARD;
Input.ki.wVk = 'A';
SendInput( 1, &Input, sizeof( INPUT ) );

// 'a' key release
Input.type = INPUT_KEYBOARD;
Input.ki.dwFlags = KEYEVENTF_KEYUP;
Input.ki.wVk = 'A';
SendInput( 1, &Input, sizeof( INPUT ) );

// shift key release
Input.type = INPUT_KEYBOARD;
Input.ki.dwFlags = KEYEVENTF_KEYUP;
Input.ki.wVk = VK_LSHIFT;
SendInput( 1, &Input, sizeof( INPUT ) );

编辑:这是另一个代码,其中包含发送信件后关闭大写/关闭的示例:
INPUT Event = { 0 };

const SHORT key = VkKeyScan('a');
const UINT mappedKey = MapVirtualKey( LOBYTE( key ), 0 );

// Press shift key
Event.type = INPUT_KEYBOARD;
Event.ki.dwFlags = KEYEVENTF_SCANCODE;
Event.ki.wScan = MapVirtualKey( VK_LSHIFT, 0 );
SendInput( 1, &Event, sizeof( Event ) );

// upper case 'A'
Event.type = INPUT_KEYBOARD;
Event.ki.dwFlags = KEYEVENTF_SCANCODE;
Event.ki.wScan = mappedKey;
SendInput( 1, &Event, sizeof( Event ) );

// release upper case 'A'
Event.type = INPUT_KEYBOARD;
Event.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
Event.ki.wScan = mappedKey;
SendInput( 1, &Event, sizeof( Event ) );

// Release shift key
Event.type = INPUT_KEYBOARD;
Event.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
Event.ki.wScan = MapVirtualKey( VK_LSHIFT, 0 );
SendInput( 1, &Event, sizeof( Event ) );

const SHORT key1 = VkKeyScan('A');
const UINT mappedKey1 = MapVirtualKey( LOBYTE( key1 ), 0 );

// lower case 'a'
Event.type = INPUT_KEYBOARD;
Event.ki.dwFlags = KEYEVENTF_SCANCODE;
Event.ki.wScan = mappedKey1;
SendInput( 1, &Event, sizeof( Event ) );

// release lower case 'a'
Event.type = INPUT_KEYBOARD;
Event.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
Event.ki.wScan = mappedKey1;
SendInput( 1, &Event, sizeof( Event ) );

解释在这里(我希望解释是正确的): SendInput() for keyboard - only uppercase

关于winapi - 键盘的 SendInput() - 只有小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11438110/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com