魔兽改键
2016-05-09 20:52
246 查看
</pre>突然间想起玩dota,网上去找改建精灵,但现在的大多下载站都会带着些东西,没有纯粹的。就想着自己写一个,搜索竟然有源代码<p></p><p><a target=_blank target="_blank" href="http://http://blog.csdn.net/sohighthesky/article/details/4550294">http://blog.csdn.net/sohighthesky/article/details/4550294</a></p><p>有些内容现在还理解不能,先照着弄一下改一下源码。</p><p>部分源码:</p><p></p><pre name="code" class="csharp">using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace war3Keywizard { public partial class Form1 : Form { public Form1() { InitializeComponent(); } war3Keywizard.KeyboardHook hook = new war3Keywizard.KeyboardHook(); private void Form1_Load(object sender, EventArgs e) { hook.OnKeyDownEvent += new KeyEventHandler(hook_OnKeyDownEvent); KeyPreview = true; } /** void hook_OnKeyDownEvent(object sender, KeyEventArgs e) { //在这里就可以截获到所有的键盘按键了 textBox1.Text = e.KeyValue.ToString(); } */ [DllImport("USER32.DLL")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", EntryPoint = "SendMessage")] private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); private const int KEY_QUOTLEFT = 219;//键盘上 [ 键的代码 private const int KEY_QUOTRIGHT = 221;//键盘上 ] 键的代码 bool isHookEnable = false;//全局变量,指示Hook是否作用 private const int WM_KEYDOWN = 0x100; private const int WM_KEYUP = 0x101; private const int WM_CHAR = 0x102; static KeyValChangeMap kMP = new KeyValChangeMap(); private void Intstart() { if (!string.IsNullOrEmpty(textBox2.Text)) { //1 kMP.insertKeypair((int)textBox2.Text[0], 97); } if (!string.IsNullOrEmpty(textBox3.Text)) { //2 kMP.insertKeypair( (int)textBox3.Text[0],98); } if (!string.IsNullOrEmpty(textBox4.Text)) { //4 kMP.insertKeypair((int)textBox4.Text[0],100); } if (!string.IsNullOrEmpty(textBox5.Text)) { //5 kMP.insertKeypair((int)textBox5.Text[0],101); } if (!string.IsNullOrEmpty(textBox6.Text)) { //7 kMP.insertKeypair( (int)textBox6.Text[0],103); } if (!string.IsNullOrEmpty(textBox7.Text)) { //9 kMP.insertKeypair( (int)textBox7.Text[0],104); } } void hook_OnKeyDownEvent(object sender, KeyEventArgs e) { textBox1.Text = e.KeyCode.ToString(); if (e.KeyCode == Keys.Scroll) { isHookEnable = !isHookEnable; string info = isHookEnable ? "quickey-开启" : "quickey-停用"; if (isHookEnable) { Intstart(); notifyIcon1.Visible = true; notifyIcon1.Text = info; } else { kMP.clear(); notifyIcon1.Visible = false; } } if (isHookEnable) { IntPtr war3 = FindWindow(null, "Warcraft III"); // IntPtr war3 = FindWindow(null, "Warcraft III"); if (war3 != IntPtr.Zero) { //SetForegroundWindow(war3);//将war3窗口置前,这一句我自己测试时可以不用,但去掉这一句后朋友那里说不行 SendMessage(war3, WM_KEYDOWN, KEY_QUOTLEFT, 0);//按下[键就可以显示友军的血了 SendMessage(war3, WM_KEYDOWN, KEY_QUOTRIGHT, 0); int finalkey = kMP.getKeyChange((int)e.KeyCode); if (finalkey != (int)e.KeyCode) { //SendMessage(war3, WM_CHAR, finalkey, 0);//按了 SendMessage(war3, WM_KEYDOWN, finalkey, 0);//按下 SendMessage(war3, WM_KEYUP, finalkey, 0);//松开 } } } } private void Form1_KeyPress(object sender, KeyPressEventArgs e) { textBox8.Text +="\r\n"+ e.KeyChar.ToString(); } } //改建的值 class KeyValChangeMap { //小键盘区键码 0=96 List<int> originKey = new List<int>(); List<int> finalKey = new List<int>(); public void insertKeypair(int keyO, int keyF) { originKey.Add(keyO); finalKey.Add(keyF); } public void clear() { originKey.Clear(); finalKey.Clear(); } public int getKeyChange(int keyO) { int loc= originKey.IndexOf(keyO); if (loc < 0) { return keyO; } else { return finalKey[loc]; } } } }
有了基本的功能,源码还有不少不懂得地方,需要继续研究和改进。
吐槽一下vs2015,真心受不了,好不容易下了个iso镜像,安装的时候貌似还跑到原站点去下了,好不容易装上了,安装个语言居然还要那么久,这一天都被耽误了。调试程序的时候可以改代码,却不让继续运行,呜呜,我在按键处打断点每次都得先删除打的字母才能调试。
相关文章推荐
- AutoHotKey写一个改键的小脚本
- controllermate for mac(改键精灵) v4.10.1 破解版
- 小常识 键盘改键
- 安卓入门--目录结构详解
- 浅析人脸检测之Haar分类器方法
- adapter的重用
- HDOJ 2049 不容易系列之(4)——考新郎
- 第十周第十一周项目2(2)
- C语言中 float double在内存中的存储
- OK6410-A开发板学习-⑦uboot移植(4) uboot起不来问题
- postgresql事务提交
- Android网络框架httplite使用指南
- Linux命令----sed和awk
- Thrift框架调研
- 特权的DIY数码相框总结
- 5.8一周总结(逻辑问题与指针)
- GitHub + VSTS 开源代码双向同步
- Halcon与MFC交互编程
- Java 集合 - ArrayList
- 获取当前Activity及Fragment名字