C# SendMessage Keypress
Programming/C# / 2010. 12. 26. 23:45
#region Function Imports
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
#endregion
#region Constants
// Messages
const int WM_KEYDOWN = 0x100;
const int WM_KEYUP = 0x101;
const int WM_CHAR = 0x105;
const int WM_SYSKEYDOWN = 0x104;
const int WM_SYSKEYUP = 0x105;
#endregion
public static void SendKey(string wName, Keys key)
{
IntPtr hWnd = FindWindow(null, wName);
SendMessage(hWnd, WM_KEYDOWN, Convert.ToInt32(key), 0);
SendMessage(hWnd, WM_KEYUP, Convert.ToInt32(key), 0);
}
public static void SendSysKey(string wName, Keys key)
{
IntPtr hWnd = FindWindow(null, wName);
SendMessage(hWnd, WM_SYSKEYDOWN, Convert.ToInt32(key), 0);
SendMessage(hWnd, WM_SYSKEYUP, Convert.ToInt32(key), 0);
}
public static void SendChar(string wName, char c)
{
IntPtr hWnd = FindWindow(null, wName);
SendMessage(hWnd, WM_CHAR, (int)c, 0);
}
반응형
'Programming > C#' 카테고리의 다른 글
[펌] 외부 응용프로그램 실행하기 (Process.Start 메서드) - CMD (0) | 2011.01.13 |
---|---|
sendmessage in C# (1) | 2010.12.27 |
윈폼에서 토글 버튼(Make Toggle Button for WinForm) 만들기 (2) | 2010.12.14 |
Microsoft Win32 to Microsoft .NET Framework API Map (0) | 2010.12.10 |
경로명,확장자 분리 함수 등등 (0) | 2010.12.09 |