本帖最后由 badboy518 于 2012-8-4 10:48 编辑
- public static class Xsys
- {
- /// <summary>
- /// 取得本dll的路径
- /// </summary>
- /// <returns></returns>
- public static string GetAssemblyPath()
- {
- string _CodeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
- _CodeBase = _CodeBase.Substring(8, _CodeBase.Length - 8); // 8是 file:// 的长度
- string[] arrSection = _CodeBase.Split(new char[] { '/' });
- string _FolderPath = "";
- for (int i = 0; i < arrSection.Length - 1; i++)
- {
- _FolderPath += arrSection[i] + "/";
- }
- return _FolderPath;
- }
- }
- /// <summary>
- /// 消息Hook,目前仅Hook了WM_KEYDOWN,事件发生时会发送回按键码
- /// </summary>
- public class MessageHook
- {
- const int WM_KEYDOWN = 0x100;
- public delegate void KeyDown(int keycode);//事件所需要的委托(注意,声明委托,必须加上括号)
- public event KeyDown OnKeyDown;//事件声明
- public void SetKeyHook()
- {
- Application.PreTranslateMessage += Application_PreTranslateMessage;
- }
- public void UnKeyHook()
- {
- Application.PreTranslateMessage -= Application_PreTranslateMessage;
- }
- void Application_PreTranslateMessage(object sender, PreTranslateMessageEventArgs e)
- {
- if (e.Message.message == WM_KEYDOWN)
- {
- //Tools.WriteMessageWithReturn(e.Message.wParam.ToString());
- OnKeyDown(e.Message.wParam.ToInt32());
- }
- }
- }
复制代码
|