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

Implement bitflag check for event key event flags. #21

Open
TimonPost opened this issue Oct 11, 2021 · 4 comments
Open

Implement bitflag check for event key event flags. #21

TimonPost opened this issue Oct 11, 2021 · 4 comments

Comments

@TimonPost
Copy link
Member

TimonPost commented Oct 11, 2021

related: #20

According to windows documentation:

[in] dwFlags
Controls various aspects of mouse motion and button clicking. This parameter can be certain combinations of the following values.

Currently, there are only checks to check against one particular case (see this file)

impl From<DWORD> for EventFlags {
    fn from(event: DWORD) -> Self {
        match event {
            0x0000 => EventFlags::PressOrRelease,
            0x0002 => EventFlags::DoubleClick,
            0x0008 => EventFlags::MouseHwheeled,
            0x0001 => EventFlags::MouseMoved,
            0x0004 => EventFlags::MouseWheeled,
            _ => panic!("Event flag {} does not exist.", event),
            _ => EventFlags::Unknown,
        }
    }

Ideally, we need to be able to detect all cases.

This also impacts: https://github.com/crossterm-rs/crossterm/blob/master/src/event/sys/windows/parse.rs#L143

And we need to find a way to handle it there as well.

@TimonPost TimonPost changed the title Implement bitflag check for event DWORD Implement bitflag check for event key event flags. Oct 11, 2021
@sigmaSd
Copy link
Contributor

sigmaSd commented Oct 11, 2021

EventFlags need to be a bitflag struct, and the varient const instance

I think that should be ok and https://github.com/crossterm-rs/crossterm/blob/master/src/event/sys/windows/parse.rs#L143 can use contains to see if a flag is set

The only probem I see is that https://github.com/crossterm-rs/crossterm/blob/master/src/event/sys/windows/parse.rs#L143 can now return a vector of events, how do you see handling this?

@sigmaSd
Copy link
Contributor

sigmaSd commented Oct 11, 2021

Basicly the question is should https://github.com/crossterm-rs/crossterm/blob/master/src/event.rs#L349 also be a bitflag struct?

If so this would make it easy to fix this issue

@sigmaSd
Copy link
Contributor

sigmaSd commented Oct 11, 2021

Or a simpler thing is to make the kind field in mouse event a vector of mouseeventkind

Also Im not sure if linux can benefit from this

@sigmaSd
Copy link
Contributor

sigmaSd commented Oct 12, 2021

@TimonPost I just noticed the msdoc page that you linked is for winapi https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mouse_event

I think the correct page is https://docs.microsoft.com/en-us/windows/console/mouse-event-record-str#members which doesn't mention that it possible to combine values

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

2 participants