1. interrupable sleep
- Posted by SnakeCharmer Dec 30, 2012
- 1346 views
I need a function, that sleep for some seconds. Waiting can be interrupted with the action. In such case that function has to return TRUE.
include std/types.e function heDidNotWait(integer Seconds) for i = 1 to Seconds do if isInterrupted() then return TRUE end if end for return FALSE end function
By the way, function isInterrupted has to return TRUE, if the castor of a mouse was turned. How to do it? Perhaps to reconstruct function?
2. Re: interrupable sleep
- Posted by ghaberek (admin) Dec 31, 2012
- 1298 views
I need a function, that sleep for some seconds. Waiting can be interrupted with the action. In such case that function has to return TRUE.
This should do the trick. Just replace my get_key() with your isInterrupted().
include "std/os.e" public function wait( atom t ) atom stop_time = time() + t while time() < stop_time do if get_key() != -1 then return 1 -- TRUE end if -- pause sleep(0) end while return 0 -- FALSE end function -- testing puts( 1, "waiting..." ) wait( 30 ) -- can be canceled by a key press puts( 1, "done!\n" )
By the way, function isInterrupted has to return TRUE, if the castor of a mouse was turned. How to do it? Perhaps to reconstruct function?
I have no idea what you mean by this. Where does isInterrupted() come from?
-Greg
3. Re: interrupable sleep
- Posted by jimcbrown (admin) Dec 31, 2012
- 1288 views
I need a function, that sleep for some seconds. Waiting can be interrupted with the action. In such case that function has to return TRUE.
This should do the trick. Just replace my get_key() with your isInterrupted().
I think what is really wanted is an implementation for isInterrupted().
By the way, function isInterrupted has to return TRUE, if the castor of a mouse was turned. How to do it? Perhaps to reconstruct function?
I have no idea what you mean by this.
-Greg
I think it means: if the cursor of the mouse was moved.
4. Re: interrupable sleep
- Posted by petelomax Dec 31, 2012
- 1360 views
I think what is really wanted is an implementation for isInterrupted().
I think it means: if the cursor of the mouse was moved.
You may want GetLastInputInfo
Pete
5. Re: interrupable sleep
- Posted by SnakeCharmer Jan 02, 2013
- 1155 views
By the way, function isInterrupted has to return TRUE, if the castor of a mouse was turned. How to do it? Perhaps to reconstruct function?
I have no idea what you mean by this.
-Greg
I mean rotation of wheel between mouse's buttons. Sorry for my poor english.
6. Re: interrupable sleep
- Posted by mattlewis (admin) Jan 02, 2013
- 1101 views
By the way, function isInterrupted has to return TRUE, if the castor of a mouse was turned. How to do it? Perhaps to reconstruct function?
I have no idea what you mean by this.
I mean rotation of wheel between mouse's buttons. Sorry for my poor english.
What sort of a program is this? Assuming you're using some GUI library, then I'd say that you'd set a timer or something, and invalidate or destroy it if you get a scroll wheel event in the meantime. If this is a console type program, that isn't using some event system, then you'll just have to periodically poll the scroll wheel.
Matt