今天同事问起Sendkeys 发送时不能带空格,因为之前被sendkeys坑过,所以想起了WindowsInput好用.改了几串代码就满足了需求.
以下实例为自动打开windows security
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using WindowsInput;
namespace winKeytest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
[DllImport("user32.dll", EntryPoint = "keybd_event")]
public static extern void keybd_event(
byte bVk, //虚拟键值
byte bScan,// 一般为0
int dwFlags, //这里是整数类型 0 为按下,2为释放
int dwExtraInfo //这里是整数类型 一般情况下设成为 0
);
private void b

本文介绍了一种使用WindowsInput库模拟键盘输入的方法,解决了Sendkeys无法发送带空格字符串的问题。通过C#代码示例,展示了如何实现自动打开Windows Security界面的过程。
最低0.47元/天 解锁文章
4456

被折叠的 条评论
为什么被折叠?



