Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inactivity in a textbox

Status
Not open for further replies.

bateman23

Programmer
Mar 2, 2001
145
DE
I've got problems with the following task:
I want to show a new form after the user hasn't done any key-presses in a textbox for a while(delay).
example:
After the user has pressed the &quot;<&quot;-Key and then waits for 2 seconds, the form should popup.
I can't use sleep, or Shellwait because then the user can't do any inputs for this time.
So the question is: How can i detect if the user is inactive?

Thanx for helping and sorry for my bad english...
 
Consider using a timer control that comes with VB for this. Set the timer to the time that you want to wait and then whenever there is activity in the textbox, simply reset the time.
- Jeff Marler B-)
 
Thanx a lot - works really good.
But, is it possible that the time isn't very exact?
Anyway - Thank you.

 
time isn't very exact? what do you mean . . . the timer control isn't very exact? If that is what you mean, then I suppose its possible (however, it should be within a few milliseconds), but then the question that I would have for you is just how accurate do you need this to be? - Jeff Marler B-)
 
I need a range between 1 and 4 seconds, and sometimes (I don't know why) it differs for one or two seconds.
-But you're right, it's not that important.
 
Your going at it all wrong bateman23......
first off a timer is not what you want to use because of the enable disable sux's when you want it to start and stop.
get rid of the TIMER....and do this..



Private Sub Text1_Change()
Do
DoEvents

Timeout (5) 'set this secs. to what you want bateman
MsgBox (&quot;Please Type Something Already will you!!!!!&quot;)

Loop

End Sub


.Now put this in your module for the timeout...........




Public Sub Timeout(duration As Long)

Dim Current As Long
Current = Timer
Do Until Timer - Current >= duration
DoEvents
Loop

End Sub


now you can set the speed of the popup as in secs. if the user does not type anything..


c-ya peep

<---CuJo There are only two things universal in this world...'Hydrogen and Stupidity'
 
replace the msgbox with the form you want...

Sorry about that I switched to Decafe' so I'm alittle slow today...


<---CuJo There are only two things universal in this world...'Hydrogen and Stupidity'
 
Cujo,
You are needlessly looping code which will wait waste CPU cycles (even with your DoEvents). The Timer option will work just fine (even with the Enable and Disable). However, if you really want performance, you need to create a custom CALLBACK using the WIN32 APIs. I don't have my API book with me at the moment, so I'll post how to do that later. In the meantime, I would still suggest tht timer option. - Jeff Marler B-)
 
You can use these API functions to create a windowless-timer.
[tt]
Declare Function SetTimer Lib &quot;user32&quot; (ByVal HWND As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long

Declare Function KillTimer Lib &quot;user32&quot; (ByVal HWND As Long, ByVal nIDEvent As Long) As Long
[/tt]
To use it, set the timer like this:
[tt]
lTimerHandle = SetTimer(0, 0, m_lInterval, AddressOf TimerHandler)

Public Sub TimerHandler(HWND As Long, uMSG As Integer, idEvent As Integer, dwTime As Double)
[tab]' Handler timer firing here
End Sub
[/tt]
and to stop it, call it like:
[tt]
KillTimer 0, lTimerHandle
[/tt]
One caveat is that the TimerHandler routine needs to be in a .BAS module, not a class module.

Chip H.
 
trust me a timer is not what you want bateman... There are only two things universal in this world...'Hydrogen and Stupidity'
 
Thanks Chip . . . those were the APIs that I was talking about. And yes, you will need a BAS module for the call back function since you can not use the AddessOf operator with an object (i.e. form, class) method. - Jeff Marler B-)
 
CuJo,
with the APIs, a timer control is not needed. You are instead creating a direct callback. Why don't you take a moment and justify your looping answer? - Jeff Marler B-)
 
On the subject of timers, Does anyone have any suggestions on how to create a timer so that any keystroke (or mousemove, altho can live without this one) in any form in the project resets the timer to 0 so that if a certain amount of time elapses without any activity (say 15 or 20 minutes) a message can appear warning the user, and then automatically quitting if no response
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top