C#中的SendKeys.Send操作CMD命令的问题

C# 虚拟键盘按键(一)【SendKeys】 有些场景下,需要模拟键盘按键的动作,而不是真正地去敲击键盘,比如使用触屏或者使用遥控器去模拟输入,这就用到虚拟键盘按键这个功能,常用的有三种方式,一种是用SendKeys去模拟输入按键,第二种是Window API的keybd_event函数,第三种也是Window API的SendInput函数(包含了模拟鼠标)。在微软的官方文档中说,第三种SendInput函数已经取代第二种keybd_event函数(能正常使用)。我们先说第一种SendKeys的使用。 阅读详情

今日需要实现通过C#操作cmd窗口的功能,在使用SendKeys.Send或SendKeys.SendWait方法进行按键模拟的时候发现,如果传入的Keys为小写开始则不被执行

代码:

            Process p = new Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.UseShellExecute = true;
            p.StartInfo.RedirectStandardInput = false;
            p.StartInfo.RedirectStandardOutput = false;
            p.StartInfo.RedirectStandardError = false;
            p.StartInfo.CreateNoWindow = false;
            p.Start();
            Thread.Sleep(2000);
            SendKeys.Send("perl -v{Enter}");

结果:


不会有任何执行。但这里如果只是用SendKeys.Send 向一个文本编辑框输入文本,那大小写都可以正常输入。

Microsoft 官方也并没有相关的解释,只是给了下面一个提示

但我个人觉得歪果仁跟我们的键盘大小写应该一样吧,这个问题也没必要深究,所以自行测试。


经过个人测试,发现问题在于输入文本的大小写,如果将“perl”改成大写开始,并且同时需要把“-v”也改成大写,这样就可以正常执行了。


总结:

在SendKeys.Send调用cmd执行cmd命令的时候,当传入小写的字符,则cmd不显示。


C# 模拟键盘输入 SendKeys用法 阅读详情

相关推荐

LaTeX双栏浮动结构实战:用dblfloatfix解决跨栏图表排版难题

本文深入探讨了LaTeX双栏浮动结构在学术论文排版中的常见问题,特别是IEEE会议论文中的跨栏图表定位难题。通过介绍dblfloatfix包的整合解决方案,帮助用户实现精准的底部定位和浮动顺序保持,提升排版效率与质量。

weixin_30872499的博客 446

C# SendKeys用法

功能:将一个或多个按键消息发送到活动窗口,就如同在键盘上进行输入一样。 语法:SendKeys.Send(string keys);SendKeys.SendWait(string keys); 说明: (1)每个按键由一个或多个字符表示。为了指定单一键盘字符,必须按字符本身的键。例如,为了表示字母 A,可以用 "A" 作为 string。为了表示多个字符,就必须在字符后面直接加...

1407

OpenAI Realtime API实时语音交互实战指南

实时语音交互是人机自然对话的核心能力,其本质在于构建低延迟、双向、流式协同的音频-语义闭环。它突破传统REST API的请求-响应范式,依托WebSocket实现毫秒级音频输入流(audio.delta)、模型生成流(text/audio.delta)与动态控制流(session.update)三重并行。该技术显著降低端到端延迟至300ms以内,支撑语音助手、智能客服、对话式教育等强实时场景。本文聚焦OpenAI Realtime API的工程落地,详解PCM音频流处理、VAD语音活动检测、AudioCon

weixin_32285357的博客 403

SendKeys.Send()的使用

使用SendKeys将键击和组合键击发送到活动应用程序。此类无法实例化。 若要发送一个键击给某个类并立即继续程序流,请使用Send。 若要等待键击启动的任何进程,请使用SendWait。   1.每个键都由一个或多个字符表示。若要指定单个键盘字符,请使用该字符本身。 例如,若要表示字母 A,请将字符串“A”传递给方法。 若要表示多个字符,请将各个附加字符追加到它

hpnets的专栏 3180

STM32驱动SPL06-001气压传感器:I2C通信与温度补偿实战

气压传感器在无人机定高、室内定位和气象监测中至关重要。SPL06-001凭借±0.06 hPa相对精度和I2C接口,成为STM32项目的理想选择。通过I2C总线读取原始数据,并利用出厂校准系数进行温度补偿和气压解算,可输出高精度气压值。本文详细解析SPL06-001的寄存器操作、校准系数拼接及补偿算法,并分享I2C上拉电阻、地址配置等避坑经验,帮助开发者快速实现气压测量与高度解算。

weixin_29188043的博客 348

6-Halcon-- var_threshold 函数功能(用于基于局部统计特性的动态阈值分割的算子)

var_threshold 是 HALCON 中用于基于局部统计特性的动态阈值分割的算子,特别适用于处理低对比度图像或纹理均匀但包含细微差异的场景。与 dyn_threshold 不同,它不依赖预处理生成的参考图像,而是直接在局部区域内计算灰度值的统计特性(均值和标准差),从而自适应调整阈值。

weixin_45590420的博客 1330

SendKeys在Windows 7登录窗口不起作用的解决方法

用户想要使用SendKeys在Windows 7登录窗口中输入密码,但是发现SendKeys不起作用。2、解决方案 使用SendKeys在Windows 7登录窗口中输入密码的方法有两个:Credential Provider Credential Provider是一种Windows Vista/7/8登录屏幕的扩展,它允许开发人员创建自定义的登录界面。要使用Credential Provider,需要实现一个C++类,并将其注册到Windows系统中。自定义GINA DLL 自定义GINA DLL是一种

D0126_的博客 513

SerDes电路的PCB仿真设计规则及策略

SerDes的PCB设计中,重点工作是使用3D 电磁 (EM) 场求解器,进行过孔结构优化,包括 BGA的扇入和扇出区域以及布线的过孔区域,并且,利用连接器供应商提供加密的 3D 模型,进行连接器和 PCB 的级联仿真,最终获取系统级的通道性能参数,如插入损耗、回波损耗、串扰和模式转换、阻抗曲线等,如果发现任何缺陷,再进行进一步优化,这一过程中,推荐进行拆分仿真,以提高设计效率。

一只豌豆象的博客 2198

Selenium环境配置全攻略:从零搭建自动化测试基础环境

Web自动化测试是软件质量保障的关键技术,其核心原理是通过程序模拟用户操作浏览器,实现测试用例的自动执行。Selenium作为该领域的标准工具,其价值在于提供了跨浏览器、跨平台的统一API,极大提升了测试效率和可重复性。在实际应用中,环境配置是自动化测试的“第一公里”,直接关系到后续脚本的稳定运行。本文聚焦于Selenium环境配置的完整流程,深入解析了浏览器驱动版本匹配、环境变量配置等核心难点,并提供了Python与Java两种主流技术栈的详细实操方案。通过理解Selenium Client、WebDri

weixin_30851867的博客 401

【2023校招】网易雷火_研发岗_笔试题解

几个月没写题,果然水平不在线了hh,AK更难实现喽,当天只AK了疯狂游戏; 题目描述和数据等尽量多的CV到了DEVC里,可能不够细节和准确; 下面进入正题,分享我们此次笔试的题目描述和代码设计吧~.........

米莱虾 4548

蓝标传媒PHP面试题(带答案)

例如数组A【1,3,5,7,9】,数组B【0,2,4,6,8】,第N个数为4,第N+1个位5。(当天最早动作时间:该时间从右侧无限接近00:00,例如00:01分早于00:02)(当天最晚动作时间:该时间从左侧无限接近00:00,例如23:59分晚于23:58)(当天最早动作时间:该时间从右侧无限接近05:00,例如05:01分早于05:02)(当天最晚动作时间:该时间从左侧无限接近05:00,例如04:59分晚于04:58)B.如果你的解法时间复杂度为O(logN),请考虑时间复杂度更低的算法。...

phpstory的博客 391

C# 发送消息SendKeys、SendMessage、keybd_event的用法

一、C#中SendKeys的用法 功能:将一个或多个按键消息发送到活动窗口,就如同在键盘上进行输入一样。 语法: SendKeys.Send(string keys); SendKeys.SendWait(string keys); 说明: (1)发送字符串 SendKeys.SendWait("A"); //发送字母A SendKeys.SendWai...

weixin_30617561的博客 1659

【YOLO目标检测全栈实战】68 模型量化:从FP32到INT8,精度不掉,速度翻倍

摘要: 模型量化能显著提升推理速度(如YOLOv5s帧率从15FPS提升至38FPS),但需避免三大误区:1)校准集需覆盖实际场景,而非随机采样;2)敏感层(如检测头)应保留FP32精度;3)预处理必须与量化前后一致。通过混合精度量化(Backbone用INT8,检测头用FP32)和逐通道量化,可实现<1%的mAP损失。关键步骤包括校准数据准备、量化感知训练及逐层精度评估,最终在Jetson Nano等边缘设备上实现速度与精度的平衡。

企鹅码农的专属播客,分享10多年的实战案例和经验解读,包含YOLO、RT-DETR、AI等各个工作领域。 154

SendKeys.Send 方法

SendKeys.Send 方法 .NET Framework (current version) .NET Framework 3.5 .NET Framework 3.0 .NET Framework 2.0 向活动应用程序发送击键。 命名空间:  System.Windows.Forms 程序集:  System.Wi

LongtengGensSupreme博客 1642

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

SendKeys.Send或SendKeys.SendWait键代码

SendKeys有两个方法,分别为Send()和SendWait()(通常用SendWait)。 使用 SendKeys 将键击和组合键击发送到活动应用程序。此类无法实例化。若要发送一个键击给某个类并立即继续程序流,请使用 Send。若要等待键击启动的任何进程,请使用 SendWait。 每个键都由一个或多个字符表示。若要指定单个键盘字符,请使用该字符本身。例如,若要表示字母 A,

突破进取务实创新,自信源自实力 3772

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

C# SendKeys.Send 方法

下面是从MSDN上摘录的关于SendKeys.Send的说明: SendKeys.Send 方法 向流动应用程序发送击键。  命名空间:System.Windows.Forms 程序集:System.Windows.Forms(在 system.windows.forms.dll 中) 语法 Visual Basic(声明)  Public Shared Sub Send

1372

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

SendKeys.SendWait()用法

此方法是模拟键盘的,所以必须传入键盘数据。 SendKeys.SendWait("{F5}"); //发送F5按键 SendKeys.SendWait("^s"); //发送 Ctrl + s 键 SendKeys.SendWait("%{F4}"); // 发送 Alt + F4 键 ...

sdywcd——jshoper3x开源商城系统作者 1325

c#中的组合键

使用   SendKeys   将键击和组合键击发送到活动应用程序。此类无法实例化。若要发送一个键击给某个类并立即继续程序流,请使用   Send。若要等待键击启动的任何进程,请使用   SendWait。         每个键都由一个或多个字符表示。若要指定单个键盘字符,请使用该字符本身。例如,若要表示字母   A,请将字符串“A”传递给方法。若要表示多个字符,请将各个附加字符追加到它之前的字

资料收集 4668

SendKeys.Send 键代码

SendKeys.Send 键代码使用   SendKeys   将键击和组合键击发送到活动应用程序。此类无法实例化。若要发送一个键击给某个类并立即继续程序流,请使用   Send。若要等待键击启动的任何进程,请使用   SendWait。         每个键都由一个或多个字符表示。若要指定单个键盘字符,请使用该字符本身。例如,若要表示字母   A,请将字符串“A”传递给方法。若要表示

何志林的专栏 4143

C# SendKeys.SendWait 方法和SendKeys.Send 方法区别

SendKeys.SendWait是要等待按键消息被处理后才返回,相当于同步的效果,类似于Win32 API里的SendMessage SendKeys.Send则将按键消息放到windows消息队列里就返回了,不会等待消息被处理,相当于异步的,类似于Win32 API里的PostMessage

zh_geo的专栏 1万+

C# 神奇的 SendKeys 类

  SendKeys.Send 方法   .NET Framework 4     其他版本 .NET Framework 4.5 .NET Framework 3.5 .NET Framework 3.0 .NET Framework 2.0 向活动应用程序发送击键。   命名空间: System.Win...

weixin_33737774的博客 1127

C#中的SendKeys发送按键消息

SendKeys.Send()     向活动应用程序发送击键SendKeys.SendWait()       向活动应用程序发送给定的键,然后等待消息被处理这两个方法可以发送组合键,需要注意的是字母按键应为小写。如全选Ctrl+A,要用SendKeys.SendWait("^a")才有效。

colin888111的专栏 1万+

winform模拟键盘操作SendKeys.Send()与SendKeys.SendWait()

在微软的帮助文档中指出SendKeys.Send()是向活动应用程序发送击键。SendKeys.SendWait()是向活动应用程序发送给定的键,然后等待消息被处理。但是在使用多线程的时候,在副线程中使用SendKeys.Send()会抛出“SendKeys 无法在此应用程序内运行,原因是此应用程序不处理 Windows 消息。请将此应用程序更改为可处理消息,或者使用 SendKeys.SendW

hqy20060698的专栏 8860

SendKeys.Send()输入中文

SendKeys有两个方法,分别为Send()和SendWait(),作用是模拟键盘输入。因为是模拟键盘输入,所以输入的字符只能是键盘上的按键,结果就是不能输入中文。 这样一来,是不是就不能输入中文了呢?让我们换一个思路:不让直接输入,复制、粘贴总可以吧。 来看看复制、粘贴的过程:先把内容复制到(系统的)剪贴板,再从剪贴板复制出来。 根据这一原理,编...

weixin_30539835的博客 1073

C# 解决模拟键盘事件SendKeys.SendWait()特殊字符转义

SendKeys.SendWait()、C#、键盘事件、用户界面特权隔离

weixin_44431073的博客 1557
上一篇: 深入理解Java的接口和抽象类
下一篇: 【一】MySql高性能优化——基础架构
Codertoy-酷玩
博客等级 码龄18年 7粉丝 17原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值