除非我移动光标,否则SendInput不会执行鼠标单击按钮.
我很感激对这一个的帮助,因为我似乎无法绕过它.
我有一个程序,在前景窗口上执行鼠标单击,我在其中使用SendInput模拟鼠标左键单击.问题是,如果我将光标移动到点击位置而不是SendInput将进行点击,但是如果我不移动光标而不是没有点击发生,即使通过我传递x和y指向MouseInputData.我想执行鼠标左键而不需要实际移动光标.
贝娄是我的课程(相当简单和直接前进)
namespace StackSolution.Classes
{
public static class SendInputClass
{
[DllImport("user32.dll", SetLastError = true)]
static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize);
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetCursorPos(out Point lpPoint);
[StructLayout(LayoutKind.Sequential)]
struct INPUT
{
public SendInputEventType type;
public MouseKeybdhardwareInputUnion mkhi;
}
[StructLayout(LayoutKind.Explicit)]
struct MouseKeybdhardwareInputUnion
{
[FieldOffset(0)]
public MouseInputData mi;
[FieldOffset(0)]
public KEYBDINPUT ki;
[FieldOffset(0)]
public HARDWAREINPUT hi;
}
[StructLayout(LayoutKind.Sequential)]
struct KEYBDINPUT
{
public ushort wVk;
public ushort …Run Code Online (Sandbox Code Playgroud) 我正在为各种模拟器制作前端并触发各种功能,例如保存/加载状态,保存屏幕截图,但具有统一的界面.FS-UAE恼人地使用"Print Screen"作为其截屏键,我想避免用户必须从默认的热键设置更改模拟器.
我已经设法用SendInput模拟我想要的任何按键,除了"打印屏幕"键.
我没有运气使用虚拟键码,我认为这不适用于全屏应用程序.因此,部分代码被注释掉了.(编辑:更好的解释 - DirectInput软件忽略虚拟密钥代码)
使用扫描码,我可以得到任何按键 - 几乎.打印屏幕似乎是奇怪的.
这是我用于扫描码的参考; https://msdn.microsoft.com/en-us/library/aa299374(v=vs.60).aspx
以下是重现问题的最低可行代码.如果你运行它,按一个键然后快速切换到记事本并等待2秒,它应按字母"q"进入记事本,然后退出.
将扫描代码从0x10(q)更改为0x37(打印屏幕),请务必在两个位置执行 - KEY DOWN和KEY UP.
现在再次运行它,按一个键然后等待.要查看"打印屏幕"是否有效,请打开MS Paint或其他任何内容,然后按CTRL + V,查看是否获得了桌面的屏幕截图.它不起作用!但是如果您手动按Print Screen,并按CTRL + V进入MS Paint,它将起作用.
为什么Print Screen键不起作用?
#include "stdafx.h"
//For create process & keyboard codes
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
int main()
{
INPUT ip = {};
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0;
ip.ki.wVk = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.dwFlags = 0;
printf("Press a key, then taskswitch.\n");
system("pause");
Sleep(2000);
//KEY DOWN
ip.ki.wScan = 0x10; //0x37 PrintScreen, 0x10 Q
ip.ki.dwFlags …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
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 ) );
Run Code Online (Sandbox Code Playgroud)
但它只会产生'a'.如何强制它生成大写?
谢谢.