我在 xp 32bits 下使用 sendInput() 使用 web 服务来推送当前焦点窗口的 F5。现在在 Vista win64 下我不能得到这个结果。一些文章指出使用 4 位或 8 位的 uint 问题,但这并不能解决 vista 下使用差分编译和 FieldOffset(4) 或 (8) 的问题。其他人则谈到使用此 SendInput() 方法的 Vista 屏幕和窗口之间不再有交互。有人可以指出在win32和win64机器上推动F5的解决方案。谢谢。
uint intReturn = 0;
NativeWIN32.INPUT structInput;
structInput = new NativeWIN32.INPUT();
structInput.type = (uint)1;
structInput.ki.wScan = 0;
structInput.ki.time = 0;
structInput.ki.dwFlags = 0;
structInput.ki.dwExtraInfo = IntPtr.Zero;
// Key down the actual key-code
structInput.ki.wVk = (ushort)NativeWIN32.VK.F5;
//vk;
intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput));
// Key up the actual key-code
structInput.ki.dwFlags = NativeWIN32.KEYEVENTF_KEYUP;
structInput.ki.wVk = (ushort)NativeWIN32.VK.F5;
//vk;
intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput));
public class NativeWIN32
{
public const ushort KEYEVENTF_KEYUP = 0x0002;
public enum VK : ushort
{
F5 = 0x74,
}
public struct KEYBDINPUT
{
public ushort wVk;
public ushort wScan;
public uint dwFlags;
public long time;
public uint dwExtraInfo;
};
[StructLayout(LayoutKind.Explicit,Size=28)]
public struct INPUT
{
[FieldOffset(0)]
public uint type;
#if x86
//32bit
[FieldOffset(4)]
#else
//64bit
[FieldOffset(8)]
#endif
public KEYBDINPUT ki;
};
[DllImport("user32.dll")]
public static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize);
}