locked
multiple keyboard events on single key RRS feed

  • Question

  • Running the code below and pressing a key once results in two separate keyboard events with the output being

    1
    1

    Kindly advise Thank You Cheerios

    #include <iostream>
    #include <cassert>
    #include <windows.h>
    
    void keyboard(HANDLE hstd_input)
    {
    	INPUT_RECORD input_record;
    	DWORD nevents = 0;
    	BOOL ok = ReadConsoleInput(hstd_input, &input_record, 1, &nevents);
    	assert(ok);
    	std::wcout << nevents << std::endl;
    }
    
    int main() 
    {
    	HANDLE hstd_input = GetStdHandle(STD_INPUT_HANDLE);
    	keyboard(hstd_input);
    	keyboard(hstd_input);
    }

    Sunday, August 30, 2020 3:39 AM

Answers

  • One event is key press, the other is key release.

    Igor Tandetnik

    Sunday, August 30, 2020 4:14 AM