Sending keystrokes to a text box 
Author Message
 Sending keystrokes to a text box

I have a textbox which I would like to move the cursor to the left after a
character is entered.  This is in a simple math application I wrote for my
8 year old and I would like to make it as automated as possible.

Here is the code I tried with no success:

Const BACKSPACE = &H8

Private Sub txtAnswer_KeyPress(KeyAscii As Integer)
    If (KeyAscii < Asc("0") Or KeyAscii > Asc("9")) And KeyAscii <>
BACKSPACE Then
        KeyAscii = 0
        Beep
    End If
End Sub

Private Sub txtAnswer_KeyUp(KeyCode As Integer, Shift As Integer)
    SendKeys "{LEFT}", True
End Sub

Note that the textbox only allows numbers and backspace.

The sendkeys statement appears to have no effect.

Any help appreciated

John Reichel



Tue, 17 Aug 1999 03:00:00 GMT  
 Sending keystrokes to a text box

Based on your description, I tried the following - which seems to work:

Private Sub txtAnswer_KeyPress(KeyAscii As Integer)
    If KeyAscii <> 8 And Chr$(KeyAscii) Like "[!0-9]" Then Exit Sub
    If KeyAscii <> 8 Then
        txtAnswer.Text = Chr$(KeyAscii) & txtAnswer.Text
        KeyAscii = 0&
    End If
End Sub

Best wishes!



Quote:

> I have a textbox which I would like to move the cursor to the left after
a
> character is entered.  This is in a simple math application I wrote for
my
> 8 year old and I would like to make it as automated as possible.

> Here is the code I tried with no success:

> Const BACKSPACE = &H8

> Private Sub txtAnswer_KeyPress(KeyAscii As Integer)
>     If (KeyAscii < Asc("0") Or KeyAscii > Asc("9")) And KeyAscii <>
> BACKSPACE Then
>         KeyAscii = 0
>         Beep
>     End If
> End Sub

> Private Sub txtAnswer_KeyUp(KeyCode As Integer, Shift As Integer)
>     SendKeys "{LEFT}", True
> End Sub

> Note that the textbox only allows numbers and backspace.

> The sendkeys statement appears to have no effect.

> Any help appreciated

> John Reichel




Wed, 18 Aug 1999 03:00:00 GMT  
 Sending keystrokes to a text box



Quote:

>I have a textbox which I would like to move the cursor to the left after a
>character is entered.  This is in a simple math application I wrote for my
>8 year old and I would like to make it as automated as possible.

>Here is the code I tried with no success:

>Const BACKSPACE = &H8

>Private Sub txtAnswer_KeyPress(KeyAscii As Integer)
>    If (KeyAscii < Asc("0") Or KeyAscii > Asc("9")) And KeyAscii <>
>BACKSPACE Then
>        KeyAscii = 0
>        Beep
>    End If
>End Sub

>Private Sub txtAnswer_KeyUp(KeyCode As Integer, Shift As Integer)
>    SendKeys "{LEFT}", True
>End Sub

>Note that the textbox only allows numbers and backspace.

>The sendkeys statement appears to have no effect.

I think what's happening is the "{Left}" is executing before the
character appears on the screen.  Try putting the SendKeys statement
in the txtAnswer_Change event instead, which doesn't fire until the
character physically appears on the screen.

Lee Weiner

"The difference between a wise man and a fool
 is that the fool never learns from his mistakes."



Wed, 18 Aug 1999 03:00:00 GMT  
 Sending keystrokes to a text box

Quote:



> >I have a textbox which I would like to move the cursor to the left after a
> >character is entered.  This is in a simple math application I wrote for my
> >8 year old and I would like to make it as automated as possible.

> >Here is the code I tried with no success:

> >Const BACKSPACE = &H8

> >Private Sub txtAnswer_KeyPress(KeyAscii As Integer)
> >    If (KeyAscii < Asc("0") Or KeyAscii > Asc("9")) And KeyAscii <>
> >BACKSPACE Then
> >        KeyAscii = 0
> >        Beep
> >    End If
> >End Sub

> >Private Sub txtAnswer_KeyUp(KeyCode As Integer, Shift As Integer)
> >    SendKeys "{LEFT}", True
> >End Sub

> >Note that the textbox only allows numbers and backspace.

> >The sendkeys statement appears to have no effect.

> I think what's happening is the "{Left}" is executing before the
> character appears on the screen.  Try putting the SendKeys statement
> in the txtAnswer_Change event instead, which doesn't fire until the
> character physically appears on the screen.

> Lee Weiner

> "The difference between a wise man and a fool
>  is that the fool never learns from his mistakes."

This is so simple you will kick yourself. Just place the following code
in the text box change event.

Text1.SelStart = 0

I have tried it and it works fine.

Anthony
--

================================================

Artificial Intelligence / Computer Science
The University of Birmingham, England
================================================



Tue, 24 Aug 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. URGENT - Sending keystrokes/text to another Windows app

2. Validating keystrokes into a Text Box

3. Text box not accepting keystrokes

4. Displaying Keystroke Combinations in a text-box

5. Rich Text Box keystroke problem

6. Sending text from one forn to a text box on another form

7. Text box text on new page text box

8. sending picture box with picture and text to a printer device

9. sending output to a text box via shell

10. How do I send list box data to a text file

11. Sending text to an input box on a web page

12. Gray Box with Black Text... sent to printer

 

 
Powered by phpBB® Forum Software