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 ...
随机推荐
- 微调Win8.1这台电脑
从前有个笑话:一位朋友在办公室受到领导教育:“我说小王同志啊,虽然这电脑是你打了报告组织上买给你用的,可是你也不好这么狂妄嘛...”可怜的他只好把图标的名字改为“大家的电脑”. 想必大家已经知道这个笑 ...
- python正则的中文处理
因工作需要,要查找中文汉字分词,因为python正则表达式\W+表示的是所有的中文字就连标点符号都包括.所以要想办法过滤掉. 参考博客:http://log.medcl.net/item/2011/0 ...
- about compiler synergy
---恢复内容开始--- you can read this page: link->; you hava insalled Cmake on you window system. of cao ...
- Python设计模式——状体模式
需求,根据当前的时间,返回工作状态 #encoding=utf-8 __author__ = 'kevinlu1010@qq.com' def get_state(hour): if hour> ...
- 【web安全】第二弹:XSS攻防中的复合编码问题
最近一直在研究XSS的攻防,特别是dom xss,问题慢慢的迁移到浏览器编码解码顺序上去. 今儿被人放鸽子,无奈在KFC看了两个小时的资料,突然有种豁然开朗的感觉. 参考资料先贴出来: 1. http ...
- ubuntu下安装ssh
vm安装ubunt后,无法连接ssh,一般情况是防火墙的问题,或者SSH没有安装. 防火墙 1.查看防火墙 sudo ufw status 2,关闭防火墙 sudo ufw disable ssh 1 ...
- CSS 实现背景半透明
IE过渡滤镜 + CSS3 rgba 即可完美实现. 具体实现代码如下: .transparent { background:rgba(0, 0, 0, 0.3); filter:pr ...
- java连接数据库时出现如下错误:
java.lang.ClassNotFoundException: com.mysql.jdbc.driver at org.apache.catalina.loader.WebappClassLoa ...
- Ubuntu14.04强化之conky——Harmattan主题
一共有17个主题,四种模式,两种天气模式,支持摄氏度和华氏度. This conky comes with 17 themes: Cards Elementary Elune Flatts Metro ...
- Hansight
http://www.hansight.com/scenarios.html#account