网站首页  词典首页

请输入您要查询的函数:

 

术语 registerhotkey
释义 RegisterHotKey
语法:
BOOL RegisterHotKey( HWND hWnd,
int id,
UINT fsModifiers,
UINT vk
);
RegisterHotKey函数
该RegisterHotKey函数定义了一个全系统热键。
参数
hWnd
[in]的窗口句柄将接收的热键产生WM_HOTKEY消息。如果该参数为NULL,WM_HOTKEY消息被张贴到调用线程的消息队列,必须在消息循环处理。
编号
[in]指定热键的标识符。如果hWnd参数为NULL,则是与热键,而不是某个特定的窗口与当前线程关联。如果热键已经存在具有相同HWND和ID参数,请参阅所采取的行动的言论。
fsModifiers
[in]指定密钥必须与压在uVirtKey参数指定的关键,以产生WM_HOTKEY消息的组合。该fsModifiers参数可以是下列值的组合。
MOD_ALT
ALT键要么必须进行了。
MOD_CONTROL
要么Ctrl键,必须追究了。
MOD_SHIFT
Shift键,要么必须进行了。
MOD_WIN
或者Windows的关键是举行了。这些键标有微软Windows徽标。键盘快捷键,涉及Windows键是由操作系统使用保留。
MOD_NOREPEAT
视窗7和更高版本:更改热键行为,以便键盘自动重复不会产生多个热键通知。

[in]指定虚拟的热键键代码。
返回值
如果函数成功,返回值为非零。
如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError。
备注
当一个键按下时,系统会禁止所有热键匹配。当找到一个匹配,系统职位的WM_HOTKEY电文与该热键关联的窗口消息队列。如果热键不与一个窗口,然后在WM_HOTKEY消息发布到与热键相关的线程。
本函数不能赞同由另一个线程创建一个窗口,一个热键。
RegisterHotKey失败如果热键指定的按键已被其他热键登记。
在Windows XP和Windows的早期版本,如果热键已经存在,它是由新的热键改为HWND和身份证相同的参数。在Windows Vista和Windows的后续版本中,如果一个热键已经存在,它是保持了与新热键随着相同HWND和身份证参数。在这些版本的Windows,应用程序必须显式调用UnregisterHotKey注销旧热键。
Windows NT4系统和Windows 2000/XP:F12键是保留给在任何时候使用调试器,因此它不应被视为一个热键登记。即使您没有调试应用程序,F12键保留的情况下内核模式调试器或一个公正,及时的调试器的居民。
应用程序必须指定范围内的0x0000到0xBFFF一个id值。共享DLL必须指定范围0xC000通过0xFFFF的一个值(范围由GlobalAddAtom函数返回)。为了避免与其他共享DLL定义热键标识符冲突,一个DLL应该使用GlobalAddAtom函数来获取热键的标识符。
实例
下面的示例显示了如何使用与MOD_NOREPEAT旗RegisterHotKey功能。在这个例子中,热键'ALT键+ b'注册的主线。当按下热键,该线程将收到WM_HOTKEY消息,将获得在挑选的getMessage调用。由于此示例使用与fsModifiers MOD_NOREPEAT价值MOD_ALT,该线程将只收到另一WM_HOTKEY消息当了'B',关键是释放,然后再同时按下Alt键被按下。
#include "stdafx.h"
int _cdecl _tmain (
int argc,
TCHAR *argv[])
{
if (RegisterHotKey(
NULL,
1,
MOD_ALT | MOD_NOREPEAT,
0x42)) //0x42 is 'b'
{
_tprintf(_T("Hotkey 'ALT+b' registered, using MOD_NOREPEAT flag\\n"));
}

MSG msg = {0};
while (GetMessage(&msg, NULL, 0, 0) != 0)
{
if (msg.message == WM_HOTKEY)
{
_tprintf(_T("WM_HOTKEY received\\n"));
}
}

return 0;
}
要下载完整的项目,请访问MSDN代码库。
功能信息
最低DLL版本 user32.dll
在Winuser.h中HeaderDeclared,头文件:winuser.h
import libraryUser32.lib
最低操作系统Windows 95,Windows NT 3.1时,Windows 7
UnicodeImplemented为Unicode版本。
参见
键盘输入,GlobalAddAtom,UnregisterHotKey,WM_HOTKEY
==英文原文==RegisterHotKey Function
The RegisterHotKey function defines a system-wide hot key.
Syntax
BOOL RegisterHotKey( HWND hWnd,
int id,
UINT fsModifiers,
UINT vk
);
Parameters
hWnd
[in] Handle to the window that will receive WM_HOTKEY messages generated by the hot key. If this parameter is NULL, WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in the message loop.
id
[in] Specifies the identifier of the hot key. If the hWnd parameter is NULL, then the hot key is associated with the current thread rather than with a particular window. If a hot key already exists with the same hWnd and id parameters, see Remarks for the action taken.
fsModifiers
[in] Specifies keys that must be pressed in combination with the key specified by the uVirtKey parameter in order to generate the WM_HOTKEY message. The fsModifiers parameter can be a combination of the following values.
MOD_ALT
Either ALT key must be held down.
MOD_CONTROL
Either CTRL key must be held down.
MOD_SHIFT
Either SHIFT key must be held down.
MOD_WIN
Either WINDOWS key was held down. These keys are labeled with the Microsoft Windows logo. Keyboard shortcuts that involve the WINDOWS key are reserved for use by the operating system.
MOD_NOREPEAT
Windows 7 and later: Changes the hotkey behavior so that the keyboard auto-repeat does not yield multiple hotkey notifications.
vk
[in] Specifies the virtual-key code of the hot key.
Return Value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError .
Remarks
When a key is pressed, the system looks for a match against all hot keys. Upon finding a match, the system posts the WM_HOTKEY message to the message queue of the window with which the hot key is associated. If the hot key is not associated with a window, then the WM_HOTKEY message is posted to the thread associated with the hot key.
This function cannot associate a hot key with a window created by another thread.
RegisterHotKey fails if the keystrokes specified for the hot key have already been registered by another hot key.
In Windows XP and previous versions of Windows, if a hot key already exists with the same hWnd and id parameters, it is replaced by the new hot key. In Windows Vista and subsequent versions of Windows, if a hot key already exists with the same hWnd and id parameters, it is maintained along with the new hot key. In these versions of Windows, the application must explicitly call UnregisterHotKey to unregister the old hot key.
Windows NT4 and Windows 2000/XP: The F12 key is reserved for use by the debugger at all times, so it should not be registered as a hot key. Even when you are not debugging an application, F12 is reserved in case a kernel-mode debugger or a just-in-time debugger is resident.
An application must specify an id value in the range 0x0000 through 0xBFFF. A shared DLL must specify a value in the range 0xC000 through 0xFFFF (the range returned by the GlobalAddAtom function). To avoid conflicts with hot-key identifiers defined by other shared DLLs, a DLL should use the GlobalAddAtom function to obtain the hot-key identifier.
Examples
The following example shows how to use the RegisterHotKey function with the MOD_NOREPEAT flag. In this example, the hotkey 'ALT+b' is registered for the main thread. When the hotkey is pressed, the thread will receive a WM_HOTKEY message, which will get picked up in the GetMessage call. Because this example uses MOD_ALT with the MOD_NOREPEAT value for fsModifiers, the thread will only receive another WM_HOTKEY message when the 'b' key is released and then pressed again while the 'ALT' key is being pressed down.

#include "stdafx.h"
int _cdecl _tmain (
int argc,
TCHAR *argv[])
{
if (RegisterHotKey(
NULL,
1,
MOD_ALT | MOD_NOREPEAT,
0x42)) //0x42 is 'b'
{
_tprintf(_T("Hotkey 'ALT+b' registered, using MOD_NOREPEAT flag\\n"));
}

MSG msg = {0};
while (GetMessage(&msg, NULL, 0, 0) != 0)
{
if (msg.message == WM_HOTKEY)
{
_tprintf(_T("WM_HOTKEY received\\n"));
}
}

return 0;
}
To download the complete project, visit MSDN Code Gallery .
Function Information
Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systemsWindows 95, Windows NT 3.1, Windows 7
UnicodeImplemented as Unicode version.
See Also
Keyboard Input , GlobalAddAtom , UnregisterHotKey , WM_HOTKEY
==原始网址==http://msdn.microsoft.com/en-us/library/ms646309(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 11:30:17