_getch not doing what I want. Need to detect key presses.

So my goal here is to detect what key's are being pressed in a while loop until I break it with enter.

adding on to my final message string like this:
keypress += _getch(); and it works fine.

My problem is _getch doesent register outside of the console application, I need it to still grab keys even if I'm not active in the console window, is this possible and if so how?
Last edited on
THe function you wan't isn't standard C++, but see if your system has a function called getkey(). That usually does what you want.
Nope no visible getkey(), Unless it's in a header that I have not included =/
closed account (E0p9LyTq)
Detecting key presses in the manner you want depends on the operating system, if it is possible at all.

Windows has GetAsyncKeyState():
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646293(v=vs.85).aspx

The problem as I read it is for the function to work properly your console window needs the keyboard focus. Needs to be the active window.

Detecting/processing keystrokes in an inactive window is possible, doing it in a console application is a lot of work.

RegisterHotKey:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646309.aspx

SetWindowsHookEx:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx
Last edited on
Topic archived. No new replies allowed.