aw0i+@andrew.cmu.edu (Andrew Jordan Werth) (04/20/88)
I have some questions about writing C programs which use messages, ports, etc. I can't seem to find some really clear source code to help me out, either... Basically, I want to add a feature to a program which blanks the screen after a specified amount of time. I am having problems in determining whether the user is doing anything with the keyboard or mouse. I originally thought I could put a loop of GetMsg's and keep track of how long it has taken since the last non-null event, but that doesn't work for two reasons: 1) It's bad for the system because I think it eats up lots of time; on a different level, 2) because it only works when the user has my window selected. How do I set up a message port which can detect input from any window whether or not my own program is actually active? Do I need to do this? Should I use the timer device at all (and if so, how? There's not much good source code around to play with...) Also, what is a way to detect the input without slowing down the whole machine? All help appreciated. Thanks. Andrew Werth aw0i@andrew.cmu.edu
dillon@CORY.BERKELEY.EDU (Matt Dillon) (04/21/88)
:Basically, I want to add a feature to a program which blanks the screen after a :specified amount of time. I am having problems in determining whether the user :is doing anything with the keyboard or mouse. :I originally thought I could put a loop of GetMsg's and keep track of how... What you are suggesting will never work... but there is a really easy way to do it! The standard solution is to add your own input handler to the system ... usually before intuition (priority 51+). This input handler would receive ALL raw mouse and keyboard events, as well as timer events every 1/10 second. Every event is timestamped, and since timer events come in continuously, you do not need to open the timer.device or anything like that. Essentially: READ RKM I about the INPUT.DEVICE READ the commented .H header files for the event structure then write a program which opens the input.device, adds your handler, then waits around for handler to signal it to do something. I will post a sample program as soon as I get home. -Matt