问题
I use VC++(VS2008 Express) to develop a C++ console application.(well, not exactly: from the console,another window(provided by 3rd party library which does not provide any API to process keypress events on the image) opens which displays a camera stream. I am new to windows programming. I like to detect the keypress of the function key(lets say F1) and change some parameters of the camera like its brightness in real time, that is, when the F1 key is pressed, i d like to see the camera stream getting brighter. I am comfortable with the camera API. That part will be OK, what i dont know is how to detect the keypress events of a specific key like the function key.
回答1:
Try reading about windows message system. You are interested in WM_KEYDOWN and WM_KEYUP as for the beginning: http://msdn.microsoft.com/en-us/library/ms646280(VS.85).aspx Most of key-press detection you may need is available through this API.
The key-codes list: http://msdn.microsoft.com/en-us/library/dd375731(v=VS.85).aspx
If this is not enough for you (maybe because you need more control), then follow to DirectInput documentation (generally useful at "gaming" level).
来源:https://stackoverflow.com/questions/6897058/runtime-keypress-detection-in-a-console-application