【发布时间】:2011-06-29 01:40:55
【问题描述】:
我最近为客户开发了一个虚拟键盘应用程序。该程序几乎适用于所有程序,但某些命令(如 {ENTER} 或 {DEL})不适用于 Citrix。是否有解决方法或替代SendKeys?
编辑 1:我尝试了 SendInput 方法(Windows 输入模拟器使用 SendInput)并且 DEL 键以及箭头键仍然不起作用。但是,ENTER 键有效。
编辑 2:已解决。使用两种不同版本的 Citrix 进行了测试。 This question helped me a lot.:
Citrix 瘦客户端使用扫描码 即使MS说keybd_event的参数 它未使用,应该为 0。你需要 同时提供物理扫描码 让 citrix 客户端获取它。 Citrix客户端也有大问题 使用生成的键盘输入 发送输入 API。
我修补了Windows Input Simulator中的代码:
// Function used to get the scan code
[DllImport("user32.dll")]
static extern uint MapVirtualKey(uint uCode, uint uMapType);
/// <summary>
/// Calls the Win32 SendInput method ...
/// </summary>
/// <param name="keyCode">The VirtualKeyCode to press</param>
public static void SimulateKeyPress(VirtualKeyCode keyCode)
{
var down = new INPUT();
down.Type = (UInt32)InputType.KEYBOARD;
down.Data.Keyboard = new KEYBDINPUT();
down.Data.Keyboard.Vk = (UInt16)keyCode;
// Scan Code here, was 0
down.Data.Keyboard.Scan = (ushort) MapVirtualKey((UInt16)keyCode, 0);
down.Data.Keyboard.Flags = 0;
down.Data.Keyboard.Time = 0;
down.Data.Keyboard.ExtraInfo = IntPtr.Zero;
var up = new INPUT();
up.Type = (UInt32)InputType.KEYBOARD;
up.Data.Keyboard = new KEYBDINPUT();
up.Data.Keyboard.Vk = (UInt16)keyCode;
// Scan Code here, was 0
up.Data.Keyboard.Scan = (ushort)MapVirtualKey((UInt16)keyCode, 0);
up.Data.Keyboard.Flags = (UInt32)KeyboardFlag.KEYUP;
up.Data.Keyboard.Time = 0;
up.Data.Keyboard.ExtraInfo = IntPtr.Zero;
INPUT[] inputList = new INPUT[2];
inputList[0] = down;
inputList[1] = up;
var numberOfSuccessfulSimulatedInputs = SendInput(2,
inputList, Marshal.SizeOf(typeof(INPUT)));
if (numberOfSuccessfulSimulatedInputs == 0)
throw new Exception(
string.Format("The key press simulation for {0} was not successful.",
keyCode));
}
【问题讨论】:
-
感谢 xsl !!!伟大的发现!我也在使用 InputSimulator (fab tool btw),但我需要你提供的这个调整 (ushort)MapVirtualKey((UInt16)keyCode, 0);出色的工作 - 非常感谢
-
你有发送整个字符串而不是按键的方法吗?
-
这可以在 Python 脚本中使用吗?
标签: c# .net sendkeys citrix virtual-keyboard