首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >缺少对RegisterHotKey的引用

缺少对RegisterHotKey的引用
EN

Stack Overflow用户
提问于 2012-01-07 14:04:17
回答 2查看 289关注 0票数 0

我在谷歌上找不到我必须使用什么参考才能使用RegisterHotKey。那是什么?

在这个主题上,如果我试图创建一个在后台监听组合键的应用程序,我应该使用RegisterHotKey吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-01-07 14:09:55

你需要一个DllImport,而不仅仅是一个推荐人。你可以在at pinvoke.net上找到更多信息。

简而言之,如果您添加:

代码语言:javascript
复制
[DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);

在您的程序中,剩下的唯一棘手的部分就是使用hWnd来注册以处理密钥。上面pinvoke.net链接的示例代码应该可以帮助您使用DllImport

票数 3
EN

Stack Overflow用户

发布于 2012-01-07 14:12:01

下面是使用C#中的RegisterHotKey函数所需的内容:

代码语言:javascript
复制
/// <summary> The RegisterHotKey function defines a system-wide hot key </summary>
/// <param name="hwnd">Handle to the window that will receive WM_HOTKEY messages generated by the hot key.</param>
/// <param name="id">Specifies the identifier of the hot key.</param>
/// <param name="fsModifiers">Specifies keys that must be pressed in combination with the key specified by the 'vk' parameter in order to generate the WM_HOTKEY message.</param>
/// <param name="vk">Specifies the virtual-key code of the hot key</param>
/// <returns><c>true</c> if the function succeeds, otherwise <c>false</c></returns>
/// <seealso cref="http://msdn.microsoft.com/en-us/library/ms646309(VS.85).aspx"/>
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8767772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档