2012-01-07 87 views
0

我无法在Google上找到我必须使用哪些参考才能使用RegisterHotKey。它是什么?缺少对RegisterHotKey的引用

虽然在这个话题上,我应该使用RegisterHotKey如果我想创建一个应用程序,在后台监听组合键?

回答

3

您需要一个DllImport,而不仅仅是一个参考。你可以找到更多的信息at pinvoke.net

总之,如果添加:

[DllImport("user32.dll")] 
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc); 

在程序的某个地方,剩下的唯一棘手的部分是想出了hWnd登记处理的关键。上面pinvoke.net链接的示例代码应该可以帮助您使用DllImport

+0

这里是我的问题。谢谢。 – HelpNeeder 2012-01-07 10:44:25

1

这里是你将需要使用RegisterHotKey功能从C#是什么:

/// <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);