LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to check the status of mouse-button/ a key press in linux using C ? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-check-the-status-of-mouse-button-a-key-press-in-linux-using-c-887870/)

001spidy 06-23-2011 01:21 AM

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...

r3sistance 06-24-2011 10:01 AM

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...

MTK358 06-24-2011 10:04 AM

Quote:

Originally Posted by r3sistance (Post 4394598)
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.

r3sistance 06-24-2011 10:21 AM

Quote:

Originally Posted by MTK358 (Post 4394600)
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.

001spidy 06-26-2011 12:14 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)...


All times are GMT -5. The time now is 09:25 PM.