Hey guys I have a wierd issue that im not sure how to fix. If a users starts timer1 it will open form that has a timer and continue allowing them to choose other options.
BUT
the sendkeys do not go through until the timer is up and the form closes.

What am I missing with this?

Examples of code below...

Case Is = "hello"
                SendKeys.SendWait("{ENTER}")
                Sleep(75)
                SendKeys.Send("hello")
                Sleep(75)
                SendKeys.SendWait("{ENTER}")

Case Is = "timer1"
                If t1 Is Nothing OrElse timer1.IsDisposed Then
                    t1 = New timer1
                    t1.Show()
                    Sleep(75)
                Else
                    t1.Show()
                    Sleep(75)
                End If

Recommended Answers

All 15 Replies

Without referring to code, what, exactly, are you trying to accomplish?

Just have a tiemr countdown in the background if someone presses one which stores timer1 and continue doing other thigns in the program :) at end of timer it just pops up a message box :)

Just have a tiemr countdown in the background if someone presses one which stores timer1

  1. Presses one what?
  2. What do you mean by "which stores timer1"?

Sorry I do not wish to explain what the program does do to NDA

I need to run a timer that count down:
WHILE its counting down i want sendkey to still work... right now it seems to hold them in memeory and then sends them after the timer is done counting.

OK, let me see if I have this correct: what you want is for to provide a timer which will wait either for n milliseconds, or until a key is pressed, correct?

It sounds to me as if what you really need is to use a separate thread for the user input. One thread would sleep a given time, then pop up the message box; the other would wait for user input, and if the user does input something in the given time, perform the requested task.

Ooo so dont use the timer class at all... Just make a sleep x seconds then have it pop up music box after... But the sleep x seconds stops the whole thing right?

How do I start a different thread?

Thank you for the idea...

So found this in my research!

Threading.Timer

I think this is the answer thatnks for the keyword!

NEver mind That does not work... threading is just for using multicore

Small program do that need that...

Again, it's hard to offer advice unless you can be clear on what it is you are trying to do. You say you want SENDKEYS to work but won't say what you want to do. I'm going to guess here that you are using SENDKEYS to control some kind of external process and that you want the timer so you can have some sort of timeout to allow time for a process to complete. That's the best I can do in the lack of any useful information.

Hey Jim,

ok Sendkeys just type into a chat box when the Case Stamenent calls them.

The timer starts and counts down and plays a .wav file at 0 then closes the form.

After thats done EVERY case statement that was called while the timer was running will start sending the keys to the chat box.

I want them to still work instantly while the tiemr is going as its just a background deal.

Right now I have the timer opening into a new form. I have also tried to keep it in the same form and it has the same effect.

Thanks!

Very confusing nomenclature! A form named timer1.

What is on the form "timer1" other than a timer that closes it?
Does the user interact with "timer1" while the creating form is executing the sendkeys code?

SendKeys simulates keyboard input by placing the requested keys into the keyboard input stream. The keyboard input stream is processed by the window that has input focus.

Is this chatbox on your form, an external application, or on a webpage in a webbrowser control? In any case, it needs to have focus for it to receive the keys sent.

In my first response I said

Without referring to code, what, exactly, are you trying to accomplish?

You don't seem to get the concept of "without code". That means you tell me what the program is supposed to do, not how you are trying to make it do it. You keep referring to timers, forms and methods (SendKeys). Those are irrelevent to the explanation of the problem.

I'm not going to waste any more time playing twenty questions with you. If you can't explain what you are doing any better than that then I suggest you show someone else who has also signed the NDA. Perhaps that person can better explain the situation.

Alright thanks for trying Jim!

Tn
Its an application like notepad. It is active it just has the form pop up with a timer counting down.

It works perfect as long as the timer form is not up.

Here is my timer code if that helps you any...

So it calls this form.

Imports System
Imports System.Timers
Imports System.Threading.Thread

Public Class DTime


    ' Create a Random object to generate random numbers. 
    Private randomizer As New Random

    ' These Integers will store the numbers 
    ' for the addition problem. 
    Private addend1 As Integer
    Private addend2 As Integer

    ' This Integer will keep track of the time left. 
    Private timeLeft As Integer

    Private Sub DTime_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Beep()
        Sleep(1000)
        timeLeft = 300
        lblTimer.Text = "300"
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick() Handles Timer1.Tick
        If timeLeft = 30 Then
            My.Computer.Audio.Play(My.Resources.d30, AudioPlayMode.Background)
            timeLeft -= 1
            lblTimer.Text = timeLeft
            Sleep(1000)
        ElseIf timeLeft > 0 Then
            ' Display the new time left 
            ' by updating the Time Left label.
            timeLeft -= 1
            lblTimer.Text = timeLeft
            Sleep(1000)
        Else
            My.Computer.Audio.Play(My.Resources.d, AudioPlayMode.Background)
            Sleep(3000)
            Me.Close()
        End If

    End Sub
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

    End Sub
End Class

Ray,

I decided to put together a sample application to show how I would do the SendKeys method. I do not recommend using SendKeys as it is has to many dependencies to work properly and is too easily messed up by other processes.

This example also shows another method using Window's messages to send and retrieve text from another process. This is much easier to control and is more reliable.

I used Notepad as the external application.

This was developed in VS2008, so when you open "Countdown.vbproj", you may have to go through an upgrade process.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.