SENDINPUT不发送击键到RDP
本文关键字:RDP SENDINPUT | 更新日期: 2023-09-27 18:09:11
使用SENDINPUT来按虚拟键对于我的应用程序在任何开放字段上都是完美的。太好了,这就是它的作用:)但是。最近有一个bug报告说它不能在RDP会话中工作。因此,我在计算机上启动记事本,扫描条形码(这就是SENDINPUT的使用方式),并将字符串放在记事本上。我启动一个RDP会话,打开记事本,没有任何东西被发送。记事本仍然是空白。因此,由于某些奇怪的原因,SENDINPUT没有通过RDP隧道。我有一种感觉,它更像是RDP会话中的设置,但我并没有天真到认为我的代码不会出错。代码没什么特别的,但我将发布重要的部分(实际调用SEND INPUT)
public class User32Input
{
public static void DoPressRawKey(byte ascii)
{
var inputs = PressRawKey(ascii);
int size = System.Runtime.InteropServices.Marshal.SizeOf(typeof(INPUT));
SendInput((uint)inputs.Count, inputs.ToArray(), size);
}
internal static System.Collections.Generic.List<INPUT> PressRawKey(byte ascii)
{
var inputs = new System.Collections.Generic.List<INPUT>();
inputs.Add(GetRawKeyDown(ascii));
inputs.Add(GetRawKeyUp(ascii));
return inputs;
}
internal static INPUT GetRawKeyDown(byte key)
{
return GetRawKey(key, KEYEVENTF_KEYDN);
}
internal static INPUT GetRawKeyUp(byte key)
{
return GetRawKey(key, KEYEVENTF_KEYUP);
}
private static INPUT GetRawKey(byte key, uint flag)
{
return new INPUT
{
type = User32Input.INPUT_KEYBOARD,
u = new InputUnion
{
ki = new KEYBDINPUT
{
wVk = key,
wScan = 0,
dwFlags = flag,
dwExtraInfo = User32Input.GetMessageExtraInfo(),
}
}
};
}
[DllImport("user32.dll", SetLastError = true)]
private static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
}
关于为什么它不能在RDP会话中工作的任何想法?
设置扫描码,RDP或ICA会话-需要KEYBDINPUT。扫描为非零。使用MapVirtualKey获取