0

我想知道是否可以在单击鼠标时按住 shift 键。

它看起来与此类似: - 如果您可以使用 SendKeys.SendWait 函数模拟鼠标点击 -SendKeys.SendWait(+{Mouseclick}); 到目前为止,我已经调用了 API“User32.dll”来调用鼠标点击:

public const int MOUSEEVENTF_LEFTDOWN = 0x2;
public const int MOUSEEVENTF_LEFTUP = 0x4;
public const int MOUSEEVENTF_MIDDLEDOWN = 0x20;
public const int MOUSEEVENTF_MIDDLEUP = 0x40;
public const int MOUSEEVENTF_RIGHTDOWN = 0x8;
public const int MOUSEEVENTF_RIGHTUP = 0x10;
[DllImport("User32.dll")]
public static extern int mouse_event(int dwFlags, int dx, int dy, int cButton, int dwExtra);

 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

然而; 是否可以同时按住Shift键?

问候, DotTutorials

4

1 回答 1

3

您应该能够使用该keybd_event功能来模拟 Shift 键。就像是:

public const int MOUSEEVENTF_LEFTDOWN = 0x2;
public const int MOUSEEVENTF_LEFTUP = 0x4;
public const int MOUSEEVENTF_MIDDLEDOWN = 0x20;
public const int MOUSEEVENTF_MIDDLEUP = 0x40;
public const int MOUSEEVENTF_RIGHTDOWN = 0x8;
public const int MOUSEEVENTF_RIGHTUP = 0x10;
public const byte KEYBDEVENTF_SHIFTVIRTUAL = 0x10;
public const byte KEYBDEVENTF_SHIFTSCANCODE = 0x2A;
public const int KEYBDEVENTF_KEYDOWN = 0;
public const int KEYBDEVENTF_KEYUP = 2;
[DllImport("User32.dll")]
public static extern int mouse_event(int dwFlags, int dx, int dy, int cButton, int dwExtra);
[DllImport("user32.dll", EntryPoint="keybd_event", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern void keybd_event(byte vk, byte scan, int flags, int extrainfo);

// shift down
keybd_event(KEYBDEVENTF_SHIFTVIRTUAL, KEYBDEVENTF_SHIFTSCANCODE, KEYBDEVENTF_KEYDOWN, 0);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
// shift up
keybd_event(KEYBDEVENTF_SHIFTVIRTUAL, KEYBDEVENTF_SHIFTSCANCODE, KEYBDEVENTF_KEYUP, 0);
于 2012-06-17T13:56:09.563 回答