C# using Sendkey function to send a key to another application
If notepad is already started, you should write:
// import the function in your class
[DllImport ("User32.dll")]
static extern int SetForegroundWindow(IntPtr point);
//...
Process p = Process.GetProcessesByName("notepad").FirstOrDefault();
if( p != null)
{
IntPtr h = p.MainWindowHandle;
SetForegroundWindow(h);
SendKeys.SendWait("k");
}
GetProcessesByName returns an array of processes, so you should get the first one (or find the one you want).
If you want to start notepad and send the key, you should write:
Process p = Process.Start("notepad.exe");
p.WaitForInputIdle();
IntPtr h = p.MainWindowHandle;
SetForegroundWindow(h);
SendKeys.SendWait("k");
The only situation in which the code may not work is when notepad is started as Administrator and your application is not.
C# using Sendkey function to send a key to another application的更多相关文章
- Extjs使用Ext.function.bind, 给句柄函数传参
回调函数updateImage中的key参数,在外部调用时有程序员自己指定. 使用Ext.Function.bind(this.updateImage, this, 'imageUrl', true) ...
- React-非dom属性-key
一.react性能 1.内容类似的尽量归到同一人组件,这样react不用每次都重新渲染 2.类似列表的内容,要加上key,可减少渲染次数 3.react渲染过程 二.代码 <!DOCTYPE h ...
- 对于json对像,怎么遍历json对象的所有key,在使用json对象时,如果无法知道key,怎么通过key变量来获取值
对于json对像,怎么遍历json对象的所有key,在使用json对象时,如果无法知道key,怎么通过key变量来获取值?请参阅下面的关键代码: <html> <head> & ...
- 使用 Node.js 做 Function Test
Info 上周 meeting 上同事说他们现在在用 java 写 function test,产生了很多冗余的代码,整个项目也变得比较臃肿.现在迫切需要个简单的模板项目能快速搭建function t ...
- Get RSA public key ASN.1 encode from a certificate in DER format
RSA public key ASN.1 encode is defined in PKCS#1 as follows: RSAPublicKey :: = SEQUENCE { modul ...
- 从C#到TypeScript - function
总目录 从C#到TypeScript - 类型 从C#到TypeScript - 高级类型 从C#到TypeScript - 变量 从C#到TypeScript - 接口 从C#到TypeScript ...
- 带有function的JSON对象的序列化与还原
JSON对象的序列化与反序列化相信大家都很熟悉了.基本的api是JSON.parse与JSON.stringify. var json={ uiModule:'http://www.a.com', ...
- 方法(method)和函数(function)的区别
函数是一段代码,通过名字来进行调用.它能将一些数据(参数)传递进去进行处理,然后返回一些数据(返回值),也可以没有返回值. 所有传递给函数的数据都是显式传递的. 方法也是一段代码,通过一个与对象相关联 ...
- Redis设置和更新Key的过期时间
EXPIRE key seconds 为给定 key 设置生存时间,当 key 过期时(生存时间为 0 ),它会被自动删除. 在 Redis 中,带有生存时间的 key 被称为『易失的』(volati ...
随机推荐
- 通过 ANE(Adobe Native Extension) 启动Andriod服务 推送消息(三)
jar包完成后,剩下就是要构建ANE包来供实际程序调用. 首先要建两个Flex库项目, default那个是官方建议加上的,仅用于不在真实环境下编译调试的时候有个默认接口不至于调用不成功报错,项目结构 ...
- 关于$.fn
今天看一篇文章,里面的一段代码出现了$.fn,第一次见到这样的写法,于是跑去问度娘...代码如下: $.fn.scrollUnique = function() { return $(this).ea ...
- CSS弹性盒模型 box-flex
目前没有浏览器支持boc-flex属性. Firefox支持代替的-moz-box-flex属性 Safari.Opera以及Chrome支持替代的-webkit-box-flex属性 box-fle ...
- 51nod1089最长回文子串V2
1089 最长回文子串 V2(Manacher算法) 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 回文串是指aba.abba.cccbccc.aaaa这种左右对称的字 ...
- PHP 生成随机浮点数
<?php /** * @desc 获取随机浮点数(支持最大最小值参数互换) * @date 2014-11-07 17:04:21 * * @param int|\最小浮点数 $min 最小浮 ...
- shell中的重定向(2>&1)
shell的输出可以分为标准输出和错误输出,2>&1中,2代表错误输出,1代表标准输出,&符号代表后面跟的是代号而不是文件. test.sh echo '我是标准输出' ls / ...
- jquery 验证插件 validate
1)required:true 必输字段(2)remote:"check.php" 使用ajax方法调用check.php验证输入值(3)email:true 必须输入正确格式的电 ...
- 实时动态更新曲线图,x轴时间s随数据的变化而变化
$(function () { $(document).ready(function () { Highcharts.setOptions({ global: ...
- oracle srvctl 命令
SRVCTL命令可以控制RAC数据库中的instance,listener以及services. 通常SRVCTL在ORACLE用户下执行.下面我们来介绍srvctl命令. 1.通过SRVCTL命令来 ...
- hdu 3480
斜率dp #include<cstdio> #include<cstring> #include<algorithm> #include<queue> ...