News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Help Please.

Started by merak316, January 20, 2007, 10:53:59 PM

Previous topic - Next topic

merak316

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.


merak316


rags

I know this is a dumb question, but what does "BUMP" mean when used as a posting?
Regards,
      Rags
God made Man, but the monkey applied the glue -DEVO

TNick


merak316

So noone interested then.

TNick

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

merak316

#6
ok ive done that works great but how could i randomise the timer instead of a set so many milleseconds?

TNick

:) 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

merak316

#8
Trying to get it to simulate spacebar being pressed, also at random intervals between a set time period for eg 1-3 minutes.



MichaelW

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

merak316

I'll give that a go invoke sleep,1 seemed to do it thanks, and Ill try that other suggestion as well cheers.

merak316

How would i go about using nrandom ive tried some variations can't seem to get it ticking.

MichaelW

Something like this:

    .IF uMsg == WM_TIMER
      ...
      invoke nrandom,2001
      add eax, 1000
      invoke SetTimer,hWin,1,eax,NULL
    .ENDIF

eschew obfuscation

merak316

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

MichaelW

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

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).
eschew obfuscation