I'm wondering how I can get it to press the spacebar every 3 minutes and be able to close if instructed, so far I have tried with the sleep api but its no good for it cant close if needed until the end of the sleep, is there a way of getting the space bar to be done randomly between set minutes etc. heres the code.
BUMP.
I know this is a dumb question, but what does "BUMP" mean when used as a posting?
Regards,
Rags
have a look (http://www.urbandictionary.com/define.php?term=bump) :P
So noone interested then.
store the time in Time1
do an infinite loop
- read the state of spacebar on each loop
IF spacebar is down, read the time in Time1
ELSE read the time in Time2
IF Time2-Time1 >=3 minutes exit
Quote from: merak316 on January 21, 2007, 06:39:48 PM
So noone interested then.
No, not really ... :green2 :green2 :green2 :green2
Nick
ok ive done that works great but how could i randomise the timer instead of a set so many milleseconds?
:) When I said that you should get the time I was thinking about GetSystemTimeAsFileTime or GetSystemTime. But why do you need to randomize the timer? What are you trying to do?
Nick
Trying to get it to simulate spacebar being pressed, also at random intervals between a set time period for eg 1-3 minutes.
One method of getting a random interval between 1000 and 3000 ms would be to get a random number in the interval 0 to 2000 by calling the nrandom function specifying a base of 2001, then add 1000 to the return value and use the result for the next timer interval.
You should be able to reduce the CPU utilization, without any significant delays in the polling loop, by inserting a "invoke Sleep,0" in the loop.
I'll give that a go invoke sleep,1 seemed to do it thanks, and Ill try that other suggestion as well cheers.
How would i go about using nrandom ive tried some variations can't seem to get it ticking.
Something like this:
.IF uMsg == WM_TIMER
...
invoke nrandom,2001
add eax, 1000
invoke SetTimer,hWin,1,eax,NULL
.ENDIF
@gogo:
cmp time,1000
je @event11
invoke Sleep,1000
mov eax, dword ptr [time]
invoke nrandom,2000
add eax, 1000
mov dword ptr [time],eax
cmp [uMsg],WM_TIMER
invoke GetAsyncKeyState,VK_F11
cmp eax,0
jz @3
mov time,0
jmp @1
not working.
You need to call SetTimer from the WM_TIMER message handler to set the new interval (time-out value). In my example I was assuming that you are using a single timer with the identifier 1. When SetTimer is called with nIDEvent set to the identifier of an existing timer, the timer is replaced with a new one that has the time-out value specified in the call.
MSDN: SetTimer (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/timers/timerreference/timerfunctions/settimer.asp)
It would be easier for us to help you if you would post all relevant parts of your code, and place the code between code tags (assuming you have scripting enabled, you can click the "#" button above the edit window to insert a pair of tags).
edit
You are not doing what I thought you were doing. Without a window, message loop, and window procedure you cannot receive WM_TIMER messages, unless you set up a specific callback function to handle the messages (TimerProc in the documentation). This is doable, but it would probably be easier to implement something like this pseudo-code:
OuterLoop:
tickCount = GetTickCount
Generate random number between 1000 and 3000
terminalCount = tickCount + random number
InnerLoop:
...
poll keyboard, etc
...
tickCount = GetTickCount
if tickCount > terminalCount then
simulate press of spacebar
goto OuterLoop
end if
goto InnerLoop
edit
merak316, what exactly are you trying to do with your code? Right now, it seems to go nowhere - if you tell us
what your goal is, we could help you more (I think) e.g. why do you need the space bar pressed?
edit
You are getting descriptions and pseudo-code instead of code because this looks like homework. You can generate the random number as I described, by calling nrandom. To understand why the timer is not working, and cannot work with your code, try the MSDN link that I provided.
If instead of:
.486
.model flat, stdcall
option casemap :none
include C:\masm32\include\windows.inc
include C:\masm32\include\kernel32.inc
include C:\masm32\include\user32.inc
includelib C:\masm32\lib\kernel32.lib
includelib C:\masm32\lib\user32.lib
You use just:
include \masm32\include\masm32rt.inc
Then you will be able to use the MASM32 macros and functions to display the value of registers, variables, etc. This will allow you to monitor what the code is actually doing, instead of having to guess.
edit
edit