-
Notifications
You must be signed in to change notification settings - Fork 6
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
Support has_event_type from libevdev #10
Comments
Yeah, I'd been meaning to add this. |
Thanks a lot! I'm going to try it out. |
It works great. However, it seems that it's not enough to determine if a device is a Keyboard or a Mouse. For that |
Yeah, I wasn't quite sure what to do with that one as it doesn't really fit the high-level API nicely. You'll see that I added It would be trivial to add a Out of interest, which event codes are you looking for? I'm not sure there's a foolproof way to distinguish device types with just the |
Yeah, My usecase is to identify all keyboard and mouse devices. In the if (!libevdev_has_event_type(dev, EV_REL) ||
!libevdev_has_event_code(dev, EV_KEY, BTN_LEFT)) {
printf("This device does not look like a mouse\n");
exit(1);
} I'm not sure how to detect a keyboard. I think using |
You were right... I needed: deviceHasEventCode :: Device -> EventType -> EventCode -> IO Bool
deviceHasEventCode dev e code = LL.hasEventCode (cDevice dev) (fromEnum' e) (fromEnum' code) Would be great if you could add it! |
Hmm, it means I also would need to have a function to construct an import Evdev (EventCode(..))
eventCodeFromKey :: Key -> EventCode
eventCodeFromKey = EventCode . fromIntegral . fromEnum |
I meant that I'd place it alongside the already-exposed lower-level stuff. In the long run, I would like to expose more of the low-level functionality, but the existing Perhaps it's time I started on that. I'm certainly overdue to return to this library, since I added a lot of stuff a few months ago that hasn't made it on to Hackage. As for your immediate issue, the |
Aah OK, makes sense.
Yeah, right now I use the following code (with the functions I mentioned above) which works fine by the way: data DeviceType
= Keyboard
| Mouse -- Mouse, TouchPad, TrackPoint, tablet
| Other
deriving Eq
enumerateDevices :: IO [(Device, DeviceType)]
enumerateDevices = do
ds <- fmap C8.pack <$> listDirectory (C8.unpack evdevDir)
traverse go (filter ("event" `C8.isPrefixOf`) ds)
where
go path = do
d <- newDevice (evdevDir <> "/" <> path)
types <- deviceEventTypes d
hasAKey <- deviceHasEventCode d EvKey (eventCodeFromKey KeyA)
hasLftBtn <- deviceHasEventCode d EvKey (eventCodeFromKey BtnLeft)
case () of
() | hasAKey -> pure (d, Keyboard)
| EvRel `elem` types && hasLftBtn -> pure (d, Mouse)
| EvAbs `elem` types && hasLftBtn -> pure (d, Mouse)
| otherwise -> pure (d, Other) |
Yeah cool, that'll probably work 99% of the time. I just wanted to point out that Linux has more robust ways of doing it. By the way, you could save some packing and unpacking etc. by using the
I should probably point to those from the README... Also, even more off-topic, but in case you haven't seen it: MultiWayIf is cool. |
I've thought about this, and I like it the way it is now. In particular, stuff like For what it's worth, you could write the relevant lines of the example as: hasAKey <- deviceHasEvent d (KeyEvent KeyA Pressed)
hasLftBtn <- deviceHasEvent d (KeyEvent BtnLeft Pressed) |
I might consider adding an |
First, thanks for making this library open source!
I'm using it to create a simple background utility to disable my keyboard's and mouse/touchpad devices when needed.
It would be nice if I could use this library to easily enumerate all keyboard and mouse input devices.
For that, I think I need libevdev_has_event_type.
Would you be willing to add this?
If so, I can see if I can create a PR for it (I'm not really familiar with Haskell's FFI, but I can try... ;-)
The text was updated successfully, but these errors were encountered: