简体   繁体   中英

How to create a shortcut in a c++ program (Keyboard input such as 'Alt' or 'Shift')

I'm trying to make a shortcut in my c++ program by using keyboard as a input. For instance, if I use "Alt" + "A" + "D", I want to change my status (predefined in program) from user to administrator. How can I make this kind of shortcut (or keyboard input) to change some feature in the program?

(Window program)

C is not the same as C++.

Compare the C11 standard n1570 to the C++11 standard n3337 .

Standard C++11 does not know about keyboards. Check by reading the standard or by looking here . For example, you can write a C++ compiler in standard C++11 (eg GCC or CLang ), and such a software does not know about keyboards. Keyboards are usually handled by operating systems (and several open source operating systems are coded in C++).

And lots of C++ programs run on computers without any keyboards: from cheap RaspBerryPi devices to TOP500 supercomputers .

If you code for Windows, you should learn and code for the WinAPI . Perhaps, as Ted Lyngmo commented, using RegisterHotKey .

If you code for a GUI, consider using a cross-platform GUI toolkit such as Qt or FLTK . Both are written in C++ and callable from C++ code. And both should work on Windows and on Linux: Your C++ code would be the same (at source level) for both Windows, Linux or MacOSX desktops.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM