how to check the status of mouse-button/ a key press in linux using C ?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how to check the status of mouse-button/ a key press in linux using C ?
Hi all,
In a C code, I need to :
1) check if a mouse button is pressed down. I need to check this status of mouse button again and again inside a loop. Depending on the status, some function will be called.
OR
2) check if some key of the keyboard is pressed down. I need to check this status of 'key' again and again inside a loop. Depending on the status, some function will be called.
Either of the two above will serve my purpose.
I am using Ubuntu 10.10.
Please help. Its urgent...
Well this seems like the wrong section and you used a forbidden word. It maybe Urgent for you, it's really not urgent for us, however since most of the post is to the point or well formed....
I have seen several things that could point you in the right direction on <insert generic search engine here> with just entering "C library mouse". This is never something I have done with C so I couldn't give anymore advice then that myself.
Overall I don't think this is going to have a simple answer as I don't think C holds a keypress status, you could do a getchar or getch but if the user is holding down multiple keys...
Also, that will only work in a terminal. I think that the OP is referring to the key being pressed no matter what window is selected.
I was thinking that too, but unless it's the OS, I can't see any real valid reasons to do that as a program should not really be scanning what an alternative program is doing. There are a few cases but they are limited at best. If it did come down to that, I am guessing that's gunna go into scanning /dev/stdin or the relevant device for the keyboard/mouse... far far out of my depth tho, perhaps there is another way, but not that I know of.
Last edited by r3sistance; 06-24-2011 at 10:26 AM.
Thank you both for the input. After a lot of googling without any real success, I adopted an alternative simpler approach to do what I wanted without scanning the input device status.... However it will be interesting if someone could find a solution to the task (in my first post above).
Pardon me if I did something wrong (this was my post on LQ)...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.