的SendKeys替代思杰的作品作品、SendKeys

2023-09-02 01:46:23 作者:聘山河作礼

我最近开发了一个客户虚拟键盘的应用程序。该方案是做工精细,几乎所有的程序,但像某些命令{ENTER} {DEL} 不工作与Citrix。是否有解决办法或替代的SendKeys

编辑1:我试过SendInput方法(视窗输入模拟器使用SendInput)和DEL键以及方向键都仍然没有工作。然而,ENTER键的作品。

编辑2:解决了这个问题。测试两个不同版本的Citrix的。 这个问题对我帮助很大:

  

的Citrix瘦客户机使用扫描code   keybd_event的参数,即使MS说:   它是未使用的,应该是0。您需要   提供物理扫描code藏汉   对于Citrix客户端得到它。   Citrix客户端也有大问题   与键盘输入与所产生的   SendInput API。

我修补的code在的Windows输入模拟器:

  //函数用于获取扫描code
[的DllImport(user32.dll中)
静态外部UINT MapVirtualKey(UINTúcode,UINT uMapType);


///<总结>
///调用Win32 SendInput方法...
///< /总结>
///< PARAM NAME =键code>在VirtualKey code至preSS< /参数>
公共静态无效SimulateKey preSS(VirtualKey code键code)
{
    VAR下来=新的输入();
    down.Type =(UInt32的)InputType.KEYBOARD;
    down.Data.Keyboard =新KEYBDINPUT();
    down.Data.Keyboard.Vk =(UINT16)键code;
    //扫描code在这里,是0
    down.Data.Keyboard.Scan =(USHORT)MapVirtualKey((UINT16)键code,0);
    down.Data.Keyboard.Flags = 0;
    down.Data.Keyboard.Time = 0;
    down.Data.Keyboard.ExtraInfo = IntPtr.Zero;

    VAR起来=新的输入();
    up.Type =(UInt32的)InputType.KEYBOARD;
    up.Data.Keyboard =新KEYBDINPUT();
    up.Data.Keyboard.Vk =(UINT16)键code;
    //扫描code在这里,是0
    up.Data.Keyboard.Scan =(USHORT)MapVirtualKey((UINT16)键code,0);
    up.Data.Keyboard.Flags =(UInt32的)KeyboardFlag.KEYUP;
    up.Data.Keyboard.Time = 0;
    up.Data.Keyboard.ExtraInfo = IntPtr.Zero;

    输入[] inputList =新的输入[2];
    inputList [0] =下来;
    inputList [1] = UP;

    变种numberOfSuccessfulSimulatedInputs = SendInput(2,
         inputList,Marshal.SizeOf(typeof运算(INPUT)));
    如果(numberOfSuccessfulSimulatedInputs == 0)
       抛出新的异常(
       的String.Format(关键preSS仿真{0}未成功。
       关键code));
}
 

解决方案

请尝试使用的Windows输入模拟器。不知道它支持思杰,但它更强大的相比的SendKeys。

I recently developed a virtual keyboard application for a customer. The program is working fine with almost all programs, but certain commands like {ENTER} or {DEL} are not working with Citrix. Is there are workaround or an alternative to SendKeys?

熊磊是好女人 没要彩礼却有陪嫁,其实她是得利者,许敏会一直告

Edit 1: I tried the SendInput method (Windows Input Simulator uses SendInput) and the DEL key as well as the arrow keys are still not working. The ENTER key works however.

Edit 2: Solved it. Tested with two different versions of Citrix. This question helped me a lot.:

Citrix thin clients uses the scancode param of keybd_event even when MS says it is unused and should be 0. You need to supply the physical scancode aswell for the citrix client to get it. Citrix client also has major problem with keyboard input generated with the SendInput API.

I patched the code in 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));
}

解决方案

Try using Windows Input Simulator. Not sure if it supports Citrix but it is much more powerfull compared to SendKeys.