我最近为客户开发了虚拟键盘应用程序。该程序几乎可以在所有程序上正常运行,但是某些命令(例如{ENTER}{DEL})不适用于Citrix。是否有解决方法或SendKeys的替代方法?

编辑1:我尝试了SendInput方法(Windows输入模拟器使用SendInput)和DEL键以及箭头键仍然无法正常工作。 ENTER键起作用。

编辑2:解决它。经过两个不同版本的Citrix测试。 This question helped me a lot.:



我在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));
}

最佳答案

尝试使用ojita不确定它是否支持Citrix,但与SendKeys相比,它的功能要强大得多。

关于c# - 适用于Citrix的SendKeys替代品,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5028872/

10-13 00:34