网站首页  词典首页

请输入您要查询的函数:

 

术语 keybd_event
释义 keybd_event
语法:
VOID keybd_event( BYTE bVk,
BYTE bScan,
DWORD dwFlags,
PTR dwExtraInfo
);
keybd_event函数
在keybd_event函数合成一个按键。该系统可以使用这种合成的击键产生WM_KEYUP或WM_KEYDOWN消息。键盘驱动程序的中断处理程序调用keybd_event函数。
视窗速查:此功能已被取代。使用SendInput代替。
参数
bVk
[in]指定虚拟键码。该代码必须在1到254的值。有关完整列表,请参阅虚拟密钥代码。
bScan
硬件扫描指定的键代码。
dwFlags
[in]的功能操作指定的各个方面。此参数可以是一个或多个下列值。
KEYEVENTF_EXTENDEDKEY
如果指定的扫描码是由前缀的值为0xE0(224)字节之前。
KEYEVENTF_KEYUP
如果指定的关键是被释放。如果没有指定,关键是被压抑。
dwExtraInfo
[in]指定一个额外的价值与关键中风。
返回值
这个函数没有返回值。
备注
应用程序可以模拟的PrintScrn键按下,以获得一个屏幕快照,并将其保存到剪贴板。要做到这一点,请keybd_event设置为VK_SNAPSHOT的bVk参数。
Windows NT/2000/XP的:在keybd_event函数可以切换NUM LOCK键,CAPS LOCK键,和Scroll Lock键。
在Windows 95/98/Me:在keybd_event函数可以切换只CAPS LOCK和SCROLL LOCK键键。它不能切换NUM LOCK键。
下面的示例程序切换使用keybd_event的NUM LOCK键灯(),其VK_NUMLOCK虚拟的关键。这需要一个布尔值,指示是否应该关闭光(假)或(真)了。同样的技术可以用于CAPS LOCK键(VK_CAPITAL)和Scroll Lock键(VK_SCROLL)。

#include
void SetNumLock( BOOL bState )
{
BYTE keyState[256];
GetKeyboardState((LPBYTE)&keyState);
if( (bState && !(keyState[VK_NUMLOCK] & 1)) ||
(!bState && (keyState[VK_NUMLOCK] & 1)) )
{
// Simulate a key press
keybd_event( VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | 0,
0 );
// Simulate a key release
keybd_event( VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
}
}
void main()
{
SetNumLock( TRUE );
}
功能信息
最低DLL版本 user32.dll
在Winuser.h中HeaderDeclared,头文件:winuser.h
import libraryUser32.lib
最低操作系统Windows 95,Windows NT 3.1
参见
键盘输入,GetAsyncKeyState,GetKeyState,keybd_event,MapVirtualKey,SetKeyboardState
==英文原文==keybd_event Function
The keybd_event function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. The keyboard driver's interrupt handler calls the keybd_event function.
Windows NT/2000/XP/Vista:This function has been superseded. Use SendInput instead.
Syntax
VOID keybd_event( BYTE bVk,
BYTE bScan,
DWORD dwFlags,
PTR dwExtraInfo
);
Parameters
bVk
[in] Specifies a virtual-key code. The code must be a value in the range 1 to 254. For a complete list, see Virtual Key Codes .
bScan
Specifies a hardware scan code for the key.
dwFlags
[in] Specifies various aspects of function operation. This parameter can be one or more of the following values.
KEYEVENTF_EXTENDEDKEY
If specified, the scan code was preceded by a prefix byte having the value 0xE0 (224).
KEYEVENTF_KEYUP
If specified, the key is being released. If not specified, the key is being depressed.
dwExtraInfo
[in] Specifies an additional value associated with the key stroke.
Return Value
This function has no return value.
Remarks
An application can simulate a press of the PRINTSCRN key in order to obtain a screen snapshot and save it to the clipboard. To do this, call keybd_event with the bVk parameter set to VK_SNAPSHOT.
Windows NT/2000/XP: The keybd_event function can toggle the NUM LOCK, CAPS LOCK, and SCROLL LOCK keys.
Windows 95/98/Me: The keybd_event function can toggle only the CAPS LOCK and SCROLL LOCK keys. It cannot toggle the NUM LOCK key.
The following sample program toggles the NUM LOCK light by using keybd_event() with a virtual key of VK_NUMLOCK. It takes a Boolean value that indicates whether the light should be turned off (FALSE) or on (TRUE). The same technique can be used for the CAPS LOCK key (VK_CAPITAL) and the SCROLL LOCK key (VK_SCROLL).

#include
void SetNumLock( BOOL bState )
{
BYTE keyState[256];
GetKeyboardState((LPBYTE)&keyState);
if( (bState && !(keyState[VK_NUMLOCK] & 1)) ||
(!bState && (keyState[VK_NUMLOCK] & 1)) )
{
// Simulate a key press
keybd_event( VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | 0,
0 );
// Simulate a key release
keybd_event( VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
}
}
void main()
{
SetNumLock( TRUE );
}
Function Information
Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systemsWindows 95, Windows NT 3.1
See Also
Keyboard Input , GetAsyncKeyState , GetKeyState , keybd_event, MapVirtualKey , SetKeyboardState
==原始网址==http://msdn.microsoft.com/en-us/library/ms646304(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:31:59