gpt4 book ai didi

c# - 如何使用 keybd_event 模拟 Ctrl A + Ctrl C

转载 作者:太空狗 更新时间:2023-10-29 22:23:11 34 4
gpt4 key购买 nike

如何模拟 Ctrl-A + Ctrl-C 使用 keybd_event?

因为我在网络浏览器表单上模拟 ctrl a + ctrl c 来复制剪贴板上的全部内容。我使用了 SendKeys.SendWait 但它没有复制全部内容!

最佳答案

这应该可行

[DllImport("user32.dll", SetLastError = true)]
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

public const int KEYEVENTF_KEYDOWN = 0x0000; // New definition
public const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Key down flag
public const int KEYEVENTF_KEYUP = 0x0002; //Key up flag
public const int VK_LCONTROL = 0xA2; //Left Control key code
public const int A = 0x41; //A key code
public const int C = 0x43; //C key code

public static void PressKeys()
{
// Hold Control down and press A
keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYDOWN, 0);
keybd_event(A, 0, KEYEVENTF_KEYDOWN, 0);
keybd_event(A, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYUP, 0);

// Hold Control down and press C
keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYDOWN, 0);
keybd_event(C, 0, KEYEVENTF_KEYDOWN, 0);
keybd_event(C, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYUP, 0);
}

关于c# - 如何使用 keybd_event 模拟 Ctrl A + Ctrl C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14395377/

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