惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Vercel News
Vercel News
F
Fortinet All Blogs
月光博客
月光博客
G
Google Developers Blog
博客园 - Franky
GbyAI
GbyAI
The Cloudflare Blog
I
InfoQ
雷峰网
雷峰网
WordPress大学
WordPress大学
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
T
The Blog of Author Tim Ferriss
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 聂微东
小众软件
小众软件
腾讯CDC
B
Blog
量子位
V
V2EX
S
SegmentFault 最新的问题
Google DeepMind News
Google DeepMind News

博客园 - liufu627

使用option 链式调用来代替异步方法幂调用 Rust 各种情况下如何修改变量 Rust 单链表的实现 Closure move 数值类型与引用类型的区别 rust 使用泛型来完成多态 # Rust异步网络编程 Rust学习 红黑树新解(删除) 红黑树新解(插入) WCF快速創建 dropdownlist - liufu627 - 博客园 ArcGIS安装 泛型OraHelper - liufu627 - 博客园 标点符号的英文说法 Hashtable 让哈希表顺序输出。 PDA datagrid问题 日期格式化 - liufu627 - 博客园 JSON.net的使用 关于C#测试Oracle数据库链接的问题
让SendKeys支持空格键 - liufu627 - 博客园
liufu627 · 2008-03-13 · via 博客园 - liufu627

  SendKeys模拟键盘的操作,设置一定的键值,便可以自动控制。但是我们在使用的过程中,发现SendKeys不支持空格键,在很多的应用场景,都需要使用空格键,所以只好通过反射的方式将其调整。
代码如下:

            Type typeForKeywords = Type.GetType("System.Windows.Forms.SendKeys+KeywordVk[], System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");


            Type typeForKeywordItem = Type.GetType("System.Windows.Forms.SendKeys+KeywordVk, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
            object objNewKey = Activator.CreateInstance(typeForKeywordItem, "SPACE", 0x20);

            Type typeForSendKeys = typeof(SendKeys);

            FieldInfo fieldForkeywords = typeForSendKeys.GetField("keywords", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Static);
            object objKeys = fieldForkeywords.GetValue(null);


            Type typeForlistForKeyword = Type.GetType("System.Collections.Generic.List`1[[System.Windows.Forms.SendKeys+KeywordVk, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
            object objForTmpKeyWords = Activator.CreateInstance(typeForlistForKeyword);

            MethodInfo mi = typeForlistForKeyword.GetMethod("Add");

            foreach (object var in (Array)objKeys)
            {
                //list.Add(var);
                mi.Invoke(objForTmpKeyWords, new object[] { var });
            }

            //list.Add(key);
            mi.Invoke(objForTmpKeyWords, new object[] { objNewKey });

            mi = typeForlistForKeyword.GetMethod("ToArray");
            object objArray = mi.Invoke(objForTmpKeyWords, null);
            fieldForkeywords.SetValue(null, objArray);