문제

I can't find on google what reference I must use to be able to use RegisterHotKey. What is it?

And while on the topic, should I use RegisterHotKey if I am trying to create an application which listen for key combination in the background?

도움이 되었습니까?

해결책

You need a DllImport, not just a reference. You can find tons more information at pinvoke.net.

In short, if you add:

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

somewhere in your program, the only remaining tricky part is coming up with the hWnd to register to handle the key. The sample code linked at pinvoke.net above should help you use the DllImport.

다른 팁

Here is what you will need to use the RegisterHotKey function from 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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top