简体   繁体   中英

AllocConsole(); with GetAsyncKeyState();

I've got some std::cout and std::cin commands between AllocConsole(); and FreeConsole();, but when I press ctrl + caps lock the console just briefly flashes by and wont cout or wait for the cin.

Is this the wrong approach to set hotkeys for bringing up the console?

if (GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(VK_CAPITAL)){ // ctrl + caps
            AllocConsole();
            ....
            ....
            ....
            ....
            FreeConsole();
        }

Thanks for your time.

Try GetAsyncKeyState(VK_CONTROL)&1

Either way, unless you put some Sleep()'s in there its just going open then close immediately.

This is definitely a job for RegisterHotKey

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