LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 06-23-2011, 01:21 AM   #1
001spidy
LQ Newbie
 
Registered: Jun 2011
Posts: 2

Rep: Reputation: Disabled
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...
 
Old 06-24-2011, 10:01 AM   #2
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
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...
 
Old 06-24-2011, 10:04 AM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Quote:
Originally Posted by r3sistance View Post
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.
 
Old 06-24-2011, 10:21 AM   #4
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by MTK358 View Post
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.
 
Old 06-26-2011, 12:14 AM   #5
001spidy
LQ Newbie
 
Registered: Jun 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
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)...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Turn the power button into a key press? jsteel Linux - General 2 04-21-2011 01:47 AM
[SOLVED] Using Keyboard key as Mouse Button (in this order) kopatops Linux - Software 7 05-09-2010 05:09 PM
How to make mid-mouse button send key press to application utahnix Linux - Software 2 10-09-2007 05:14 PM
Beryl crashes X server if I move mouse or press a key! dezireduser Linux - Software 2 12-13-2006 01:58 PM
Map Mouse Button to Key Parksy Linux - Hardware 0 01-07-2004 08:00 PM


All times are GMT -5. The time now is 11:40 AM.

Main Menu
Advertisement
My LQ
Write for 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.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration