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 ...
随机推荐
- sql 修改字段小记
增加字段默认值: alter table 表名 ADD 字段 类型 NULL Default 0 修改字段类型: alter table 表名 alter column UnitPrice decim ...
- 挑战EXT——QUI框架介绍与下载
挑战EXT——QUI框架介绍与下载 为庆祝新版QUI问世特写此文: 提起EXTJS的大名,恐怕WEB开发界无人不晓吧.EXTJS框架发展到现在,已经非常成熟和全面了.它的组件库尤其是DataGrid组 ...
- Oracle 自连接 / 外连接 / 子查询
--连接查询的三种格式 select ename, deptno,dname from emp natural join dept; select ename, deptno,dname from e ...
- Memcached 缓存个体,对象,泛型,表
转自 :http://www.cnblogs.com/panshengqiang/p/3605599.html 下面是两位大牛关于Memcached的介绍:大家可以看看 http://zhoufoxc ...
- PHP引用传值规范问题
在我上一篇: shopnc 商城源码阅读笔记--开篇概述 中,遇到了一个PHP引用传值导致的错误,情况大致如下: 在我查阅PHP官方文档 的中文版的时候 http://php.net/ma ...
- java 调用oracle 分页存储过程 返回游标数据集
1.分页类 package org.zh.basic; /** * 页面类 * * @author keven * */ public class PageInfo { // 定义 private S ...
- 【配置文件节点】java世界配置文件节点
Spring <context:property-placeholder/> 期望:能不能有一种解决方案可以方便我们在一个阶段内不需要频繁书写一个参数的值,而在不同阶段间又可以方便的切换参 ...
- unity3d 使用背景贴图
使用贴图代替天空盒作为背景,参照:http://www.narkii.com/club/thread-261840-1.html 看看我做的:
- Unity3d Shader开发(四)UsePass ,GrabPass ,SubShader Tags
(一)UsePass 命令 使用 来自另一个着色器的命名通道. Syntax 语法 UsePass "Shader/Name" 插入所有来自给定着色器中的给定名字的通道.Shade ...
- 扩展pl0编译器设计——总述
所谓编译器,实际上就是我们编程时将输入的高级语言代码转换成相应的目标代码,从而实现将目标代码转换成汇编码的一种过渡工具. 这种工具根据具体情况不同,可以将不同的高级语言代码转换成不同的目标代码,例如将 ...