[转][C#]一段软键盘代码

InputSimulator sim = new InputSimulator();
[DllImport("user32.dll")]
private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

private const int GWL_EXSTYLE = -20;

private const int WS_EX_NOACTIVATE = 0x08000000;
public Form1()
{
    InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
    SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) | WS_EX_NOACTIVATE);
}

private void button1_Click(object sender, EventArgs e)
{
    sim.Keyboard.KeyPress(VirtualKeyCode.ENTER);
}

private void button2_Click(object sender, EventArgs e)
{
    sim.Keyboard.KeyPress(VirtualKeyCode.BACK);
}

private void button3_Click(object sender, EventArgs e)
{
    sim.Keyboard.KeyPress(VirtualKeyCode.VK_3);
}

 

posted on 2020-07-23 21:47  z5337  阅读(331)  评论(0编辑  收藏  举报