C Language Console window graphics interface programming seven keyboard events

Source: Internet
Author: User
Tags bool delete key function prototype

The keyboard events in the input event usually have character events and keystroke events, and the accompanying information for these events forms the information that the keyboard enters, and the attempt to read the information is obtained through API function Readconsoleinput, which is the following function prototype:

BOOL readconsoleinput (//              read input information    
    HANDLE hconsoleinput,/           /handle    
    Pinput_record lpbuffer,         // Enter the pointer DWORD nlength of the event structure body,////The                  number of records to read    
    Lpdword lpnumberofeventsread    //The pointer  used to accept the number of successful reads If the function is invoked successfully, a pointer that returns a non-0 value    
//input event structure body can be the first address of an array of structures, so that multiple records can be read at one time.

Here are a few of the structures that are related to reading the keyboard input events, each with the following structure prototypes:

typedef struct _INPUT_RECORD//input event structure body {WORD eventtype;     Event Type Union {Key_event_record keyevent;   Key event Mouse_event_record MouseEvent;    
        Mouse event Window_buffer_size_record windowbuffersizeevent;    
        Menu_event_record menuevent;    
    Focus_event_record FocusEvent;    } Event;    
Specific event} Input_record; /* There are 5 kinds of values for event type EventType Key_event representing event contains a KEY_EVENT_RECODE structure mouse_event representative                  The event contains a mouse_event_recode struct window_buffer_size_event representing an event containing a WINDOW_BUFFER_SIZE_EVENT_RECORD structure menu_event
        
Represents an event containing a Menu_event_record structure focus_event representing an event containing a FOCUS_EVENT_RECORD structure body * *             typedef struct _KEY_EVENT_RECORD//keyboard event structural body {BOOL bkeydown;         The key state, true for the key press, false for the key to release WORD Wrepeatcount;    Key times WORD Wvirtualkeycode;  Virtual key WORD Wvirtualscancode;      Virtual key Scan Code Union {WCHAR Unicodechar;        interpreted as Unicode wide character char Asciichar;    
    Interpreted as ASCII code character} Uchar;    DWORD dwcontrolkeystate;    
Control key State} Key_event_record; /* The value of the state of the control key enhanced_key the extension key is pressed down left_alt_pressed left ALT key is pressed left_ctrl_pressed left CTRL key is pressed Right_alt _pressed Right ALT key is pressed down right_ctrl_pressed right CTRL key is pressed numlock_on number lock is turned on scrolllock_on Scroll lock is opened CAPS LOCK_ON caps Lock is turned on shift_pressed SHIFT key is pressed/

When the input event is a keyboard event, the event type is the keyboard event, and for other events, the event type is the corresponding event. In addition, each meaningful key on the keyboard corresponds to a unique scan code, although the scan code can be used as the key identification, but it is dependent on the specific device. Therefore, in an application, it is often the virtual key code that is not related to the specific device. This virtual key code is a device-independent keyboard encoding. and control key state such as CAPS Lock open state, CTRL press State and so on 、、、

The following are some common virtual key code tables:

/* Virtual key code value key name-----------------------------------------------------Vk_back 0 x08 backspace vk_tab 0x09 TAB vk_return 0x0D return key Vk_shift 0x10 SHIFT Key Vk_lshift 0xa0 left SHIFT key Vk_rshift 0XA1 right SHIFT key Vk_control 0x11 CTRL key VK        _lcontrol 0xa2 Left Ctrl key Vk_rcontrol 0XA3 right CTRL key Vk_menu 0x12 ALT key Vk_lmenu        0xa4 left ALT key Vk_rmenu 0xa5 right ALT key Vk_pause 0x13 PAUSE key Vk_capital Caps lock key Vk_numlock 0x90 num LOCK key vk_scroll 0x91 SCROLL lock key Vk_escape 0        X1B ESC key Vk_space 0x20 SPACEBAR Vk_prior 0x21 Page up key Vk_next 0x22   
Page down key vk_end 0x23 end key Vk_home 0x24 Home key Vk_left 0x25 left ARROW key   Vk_up 0x26     Up ARROW key Vk_right 0x27 right ARROW key Vk_down 0x28 down ARROW key Vk_delete 0x2e DELETE key Vk_insert 0x2d INSERT key ' 0 ' 0x30 0 key (non-keypad) ' 1 ' 0x31 1 key (non-keypad) '   
2 ' 0x32 2 key (non-keypad) ...             ' 9 ' 0x39 9 key (non keypad) ' A ' 0x41 ' B ' 0x42 b key ...   
...         ...      ' Z ' 0x5a z key vk_sleep 0x5f sleep key vk_numpad0 0x60 keypad 0 Key Vk_numpad1   
0x61 keypad 1 keys vk_numpad2 0x62 keypad 2 keys .... VK_NUMPAD9 0x69 keypad 9 keys vk_multiply 0x6a Keypad multiplier * Vk_add 0x6b keypad plus + Vk_subtra   
CT 0x6d Keypad Subtraction-vk_divide 0x6f keypad removal key/vk_decimal 0x6e keypad dot key.     VK_F1 0x70 F1 key vk_f2 0x71 F2 key ...    ...         VK_F12 0x7b F12 key vk_f13 0x7c F13 Key Note: Don't ask me, I don't know what computer has so many keys ...   
...        Vk_f24 0x87 F24 key vk_oem_1 0xBA;: Key vk_oem_2 0xBF/? Key Vk_oem_3   
0XC0 ~ key Vk_oem_4 0xDB [{key vk_oem_5 0xDC \| key vk_oem_6 0xDD]} key    Vk_oem_7 0xDE ' "Key vk_oem_plus 0xBB =+ key vk_oem_minus 0xBD-_ key Vk_oem_comma 0xBC,< key vk_oem_period 0xBE .> key

The above is a part of the commonly used Microsoft Virtual keyboard code table, want to know more detailed, see MSDN. The specific use of each virtual key varies depending on the compiler or IDE. Here is a sample program that outputs ESC by pressing the ESC key:

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/C/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.