Simulate holding the Enter key down

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

I have a form that generates random numbers. If I press the command button
once I get a random number, and that works great. But I have noticed that if
I hold the Enter key down the random numbers appear to Animate or change very
quickly. Is there a way in VBA to automate holding the "Enter key" for say
20 seconds? I was looking at the timer event. But no luck.

Thanks
Richard
 
Richard said:
I have a form that generates random numbers. If I press the command button
once I get a random number, and that works great. But I have noticed that if
I hold the Enter key down the random numbers appear to Animate or change very
quickly. Is there a way in VBA to automate holding the "Enter key" for say
20 seconds? I was looking at the timer event. But no luck.

Thanks
Richard

Sounds to me as if the Enter key is simply auto-repeating, rather than
changing state, as the Shift or Control keys do. Sure, you could use
the Sendkeys statment in VBA to do this, but I have no doubt there will
be a better way!

Phil, London
 
Why do you need to do this?

For instance, if you are always getting the same random number(s) generated
then you may just need to fix the random number generation routine you are using.

You could use VBA code and create a loop that would call the code that is
generating the random number - either a specified number of times or for a
specified duration.

You might consider posting the code you are currently using if you want
someone to suggest exactly how to do what you want.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
Richard -

Why would you want to do that? If this is a random number, why would it
matter if you clicked the button once or a thousand times (since holding the
Enter key down is like repeatedly clicking on the button)? In eather case
you still end up with a random number...
 
Daryl S

It's just a visual thing has nothing to do with the random number. I
was experimenting with a slot machine look to the random number, where it
would roll for a few seconds then stop on a random number.

Richard
 
Richard said:
I have a form that generates random numbers. If I press the command button
once I get a random number, and that works great. But I have noticed that
if
I hold the Enter key down the random numbers appear to Animate or change
very
quickly. Is there a way in VBA to automate holding the "Enter key" for
say
20 seconds? I was looking at the timer event. But no luck.


I think what you are talking about is the effect of triggering the command
button's Click event repeatedly by holding down the Enter key (and thus
generating a series of repeated keystrokes). In VBA, you could use the
form's Timer event to call the command button's Click event. To do that,
you would set the form's TimerInterval property to some suitable value --
1000 would fire the time every second, 100 would fire it every tenth of a
second, etc. -- and have a Timer event procedure for the form similar to
this:

Private Sub Form_Timer()

Call Command0_Click

End Sub

where "Command0" is the name of your command button.
 
Very cool thank you!

Richard

Dirk Goldgar said:
I think what you are talking about is the effect of triggering the command
button's Click event repeatedly by holding down the Enter key (and thus
generating a series of repeated keystrokes). In VBA, you could use the
form's Timer event to call the command button's Click event. To do that,
you would set the form's TimerInterval property to some suitable value --
1000 would fire the time every second, 100 would fire it every tenth of a
second, etc. -- and have a Timer event procedure for the form similar to
this:

Private Sub Form_Timer()

Call Command0_Click

End Sub

where "Command0" is the name of your command button.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 
Back
Top