[DllImport("coredll")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
Declare Function SendMessage Lib "coredll.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As IntPtr
If you are searching for a way to send keys to an application, you can use System.Windows.Forms.SendKeys.Send(keys) after bringing the window to the top via the SetForegroundWindow API.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//Down
User32.SendMessage(listView1.Handle, User32.WM.WM_KEYDOWN, (int)User32.VK.VK_DOWN, 0);
User32.SendMessage(listView1.Handle, User32.WM.WM_KEYUP, (int)User32.VK.VK_DOWN, 0);
}
private void button2_Click(object sender, EventArgs e)
{
//Up
User32.SendMessage(listView1.Handle, User32.WM.WM_KEYDOWN, (int)User32.VK.VK_UP, 0);
User32.SendMessage(listView1.Handle, User32.WM.WM_KEYUP, (int)User32.VK.VK_UP, 0);
}
//Left ... Right...
}
class User32
{
[System.Runtime.InteropServices.DllImport("coredll.dll")]
public static extern int SendMessage(IntPtr hWnd, WM Msg, int wParam, int lParam);
public enum VK : int
private void button2_Click(object sender, EventArgs e)
{
VK_DOWN = 0x28,
VK_UP = 0x26,
VK_LEFT = 0x25,
VK_RIGHT = 0x27
}
//Up
User32.SendMessage(listView1.Handle, User32.WM.WM_KEYDOWN, (int)User32.VK.VK_UP, 0);
User32.SendMessage(listView1.Handle, User32.WM.WM_KEYUP, (int)User32.VK.VK_UP, 0);
public enum WM
{
WM_KEYUP = 0x0101,
WM_KEYDOWN = 0x0100
}
}
//Left ... Right...
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
class User32
{
[System.Runtime.InteropServices.DllImport("coredll.dll")]
public static extern int SendMessage(IntPtr hWnd, WM Msg, int wParam, int lParam);
public enum VK : int
{
VK_DOWN = 0x28,
VK_UP = 0x26,
VK_LEFT = 0x25,
VK_RIGHT = 0x27
}
public enum WM
{
WM_KEYUP = 0x0101,
WM_KEYDOWN = 0x0100
}
}
Do you know one? Please contribute it!