我在谷歌上找不到我必须使用什么参考才能使用RegisterHotKey。那是什么?
在这个主题上,如果我试图创建一个在后台监听组合键的应用程序,我应该使用RegisterHotKey吗?
发布于 2012-01-07 14:09:55
你需要一个DllImport,而不仅仅是一个推荐人。你可以在at pinvoke.net上找到更多信息。
简而言之,如果您添加:
[DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);在您的程序中,剩下的唯一棘手的部分就是使用hWnd来注册以处理密钥。上面pinvoke.net链接的示例代码应该可以帮助您使用DllImport。
发布于 2012-01-07 14:12:01
下面是使用C#中的RegisterHotKey函数所需的内容:
/// <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);https://stackoverflow.com/questions/8767772
复制相似问题