Dobry den, rad bych porosil nekoho o radu ohledne ovladani tohoto APIcka. At delam co delam nemuzu zmacknout tlacitko. Predpokladam ze to asi bude jen nejaka banalita ale ja proste netusim jak. Postupoval jsem podle MSDNka a pinvoke.net ale nemohu se zdarne dobrat k cili.
Ve finale by mel program po klepnuti do jakekoliv textove casti ve windows(i vzdalene sprave) vyslat urcite znaky. Nic mene budu rad kdyby mi aspon nejaka dobra duse ukazala jak posilat tlacitk :-)
Predem Diky
Muj nefunkcni kod(nehlasi chybu a SendInput mi stale vraci hodnotu 0)
[[DllImport("user32.dll", EntryPoint = "SendInput", SetLastError = true)]
static extern uint SendInput(
uint nInputs,
INPUT[] pInputs,
int cbSize);
[DllImport("user32.dll", EntryPoint = "GetMessageExtraInfo", SetLastError = true)]
static extern IntPtr GetMessageExtraInfo();
private enum InputType
{
INPUT_MOUSE = 0,
INPUT_KEYBOARD = 1,
INPUT_HARDWARE = 2,
}
[Flags()]
private enum KEYEVENTF
{
EXTENDEDKEY = 0x0001,
KEYUP = 0x0002,
UNICODE = 0x0004,
SCANCODE = 0x0008,
}
[StructLayout(LayoutKind.Sequential)]
private struct KEYBDINPUT
{
public short wVk;
public short wScan;
public int dwFlags;
public int time;
public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Explicit)]
private struct INPUT
{
[FieldOffset(0)]
public int type;
[FieldOffset(4)]
public KEYBDINPUT ki;
}
//predpokladam ze chyba asi bude nekde zde pac nejak jsem se nedocetl jak nastavit dwFlags aby poslal patricny key(brany z enumu VK)
public void KayPress()
{
INPUT structInput = new INPUT();
structInput.type = (int)InputType.INPUT_KEYBOARD;
structInput.ki.wScan = 0;
structInput.ki.time = 0;
structInput.ki.dwFlags = (int)KEYEVENTF.UNICODE;
structInput.ki.wVk = (short)VK.LWIN;
INPUT[] input = { structInput };
uint neco = SendInput(1, input, Marshal.SizeOf(structInput));
}