Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key press and release events are sent on press only on windows #289

Open
LelouBil opened this issue Aug 7, 2024 · 0 comments
Open

Key press and release events are sent on press only on windows #289

LelouBil opened this issue Aug 7, 2024 · 0 comments

Comments

@LelouBil
Copy link

LelouBil commented Aug 7, 2024

Hello, I am not sure if this is doable easly in Java, but if you use this simple C++ windows application in CLion and enabled "emulate terminal in output console"

#include <stdio.h>
#include <stdbool.h>
#include <windows.h>
#include <iostream>

bool getconchar( KEY_EVENT_RECORD& krec )
{
DWORD cc;
INPUT_RECORD irec;
HANDLE h = GetStdHandle( STD_INPUT_HANDLE );

if (h == NULL)
{
return false; // console not found
}

for( ; ; )
{
ReadConsoleInput( h, &irec, 1, &cc );
if( irec.EventType == KEY_EVENT
)//&& ! ((KEY_EVENT_RECORD&)irec.Event).wRepeatCount )
{
krec= (KEY_EVENT_RECORD&)irec.Event;
return true;
}
}
return false; //future ????
}

int main( )
{
    std::cout << "Press any key to see its code" << std::endl;
    KEY_EVENT_RECORD key;
    for( ; ; )
    {
        getconchar( key );
        std::cout << "key: " << key.uChar.AsciiChar
                  << " code:  " << key.wVirtualKeyCode
                  << " down: " << key.bKeyDown <<
                  std::endl;
    }
}

You can see that both events appear at the same time.
If you use "Run in External Console" and use the latest version of Windows terminal or windows conhost the events work correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant