V prvom rade, pozor na terminologiu. SendKeys.Send(), ani KeyCode nie su skripty.
V druhom rade, pomocou metody Send() triedy SendKeys nie je mozne simulovat uvolnenie klavesy.
Pomocou WinAPI funkcie SendMessage to uz mozne je. No skor ako ti sem hodim priklad, napis, naco taku simulaciu potrebujes, pretoze WinAPI funkcie by som bral ako poslednu moznost.
//autoeditácia príspevku (22 Júl 2012, 11:40)
Obetoval som par minut zo svojho casu a vytvoril jednoduchu ukazkovu triedu:
VB.NET:
Kód: Vybrať všetko
Public Class InputSimulator
<DllImport("user32.dll", EntryPoint:="SendMessage")> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal message As UInteger, ByVal wParam As ULong, ByVal lParam As ULong) As Long
End Function
Private ReadOnly WM_LBUTTONUP As UInteger = &H202
Private ReadOnly WM_LBUTTONDOWN As UInteger = &H201
Private ReadOnly WM_KEYDOWN As UInteger = &H100
Private ReadOnly WM_KEYUP As UInteger = &H101
Public Sub SendLeftMouseUp(ByVal handle As IntPtr)
SendMessage(handle, WM_LBUTTONUP, 0, 0)
End Sub
Public Sub SendLeftMouseDown(ByVal handle As IntPtr)
SendMessage(handle, WM_LBUTTONDOWN, 0, 0)
End Sub
Public Sub SendKeyUp(ByVal handle As IntPtr, ByVal key As Keys)
SendMessage(handle, WM_KEYUP, CType(key, ULong), 0)
End Sub
Public Sub SendKeyDown(ByVal handle As IntPtr, ByVal key As Keys)
SendMessage(handle, WM_KEYDOWN, CType(key, ULong), 0)
End Sub
End Class
C#:
Kód: Vybrať všetko
public class InputSimulator
{
[DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern long SendMessage(IntPtr hWnd, uint message, ulong wParam, long lParam);
private readonly uint WM_LBUTTONUP = 0x0202;
private readonly uint WM_LBUTTONDOWN = 0x0201;
private readonly uint WM_KEYDOWN = 0x0100;
private readonly uint WM_KEYUP = 0x0101;
public void SendLeftMouseUp(IntPtr handle)
{
SendMessage(handle, WM_LBUTTONUP, 0, 0);
}
public void SendLeftMouseDown(IntPtr handle)
{
SendMessage(handle, WM_LBUTTONDOWN, 0, 0);
}
public void SendKeyUp(IntPtr handle, Keys key)
{
SendMessage(handle, WM_KEYUP, (ulong)key, 0);
}
public void SendKeyDown(IntPtr handle, Keys key)
{
SendMessage(handle, WM_KEYDOWN, (ulong)key, 0);
}
}
No i tak radsej napis, aky problem riesis simulaciou stlacenia klaves. Je pravdepodobne, ze ho riesis zbytocne komplikovane.