| Код | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices;
namespace ConsoleApplication1 {
public struct KEYBDINPUT { //Перечитал много разных доков, примеров и форумов, перепробовал много разных типов данных (short, byte, int и пр.) public ushort wVk; public ushort wScan; public uint dwFlags; public long time; public IntPtr dwExtraInfo; }; public struct INPUT { public uint type; public KEYBDINPUT ki; }; public enum VK: ushort { VK_LWIN=0x5B, //Список кодов клавишь взят с www.pinvoke.net, он длинный, оставим только эту } class Program { [DllImport("user32.dll", SetLastError=true)] static extern uint SendInput(uint nInputs, INPUT pInputs, int cbSize);
static void Main(string[] args) { System.Threading.Thread.Sleep(3000);
uint intReturn; INPUT structInput; structInput = new INPUT(); structInput.type = 1; structInput.ki.wScan = 0; structInput.ki.time = 0; structInput.ki.dwFlags = 0;
structInput.ki.wVk = 0x5B; intReturn = SendInput(1, structInput, Marshal.SizeOf(structInput));
structInput.ki.dwFlags = 2; intReturn = SendInput(1, structInput, Marshal.SizeOf(structInput));
Console.WriteLine(intReturn); Console.ReadLine(); } } }
|
sendinput возвращает стабильно 0 (то есть не срабатывает ниразу), сколько вариантов я не испробовал. |