Replacing Text Automatically - VB8

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BlueDragon
    New Member
    • Mar 2012
    • 3

    Replacing Text Automatically - VB8

    This was asked on CodeProject also but I haven't received a working reply so am posting here. The only reply I did get there suggested using "e.Handled = true" but that didn't work no matter where I put it.

    Below is the section I'm having trouble with at the moment:

    Code:
        Friend Sub glbHooks_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles glbHooks.KeyPress
            newStr = newStr & LCase(e.KeyChar)
            n = 0
     
            If e.KeyChar = vbBack Then
                tmpStr = ""
                For i = 1 To newStr.Length
                    If i < newStr.Length - 1 Then tmpStr = tmpStr & newStr.Substring(i - 1, 1)
                Next
                newStr = tmpStr
            End If
     
            If newStr.Length = 4 Then
                If newStr(3) = "-" Then
                    If InStr(rkSet, newStr) Then
                        n = 1
                        My.Computer.Keyboard.SendKeys(Chr(8) & Chr(8) & Chr(8) & dicRepStr(newStr))
                        newStr = ""
                    End If
     
                End If
     
                tmpStr = ""
                For i = 1 To newStr.Length
                    If i <> 1 Then tmpStr = tmpStr & newStr.Substring(i - 1, 1)
                Next
                newStr = tmpStr
            End If
     
            If n = 1 Then
                Sleep(100)
                My.Computer.Keyboard.SendKeys(Chr(8) & " ")
            End If
        End Sub
    What this is supposed to do is replace a 4-char usercode with user's choice of text. It works great but it adds a dash {-} at the end of the replacement text. The user chooses which symbol is the trigger and in my tests I'm using the dash. Which means the program is including the last-typed character.

    I added the last "If" statement to try and remove it then add a space but it does no good. It just puts the dash AFTER the space.

    Also, if I put "If n = 1 Then My.Computer.Key board.SendKeys( Chr(8))" at the beginning of this Sub then it will remove the dash after typing the next character. BTW the "Chr(8)" I tried when the "vbBack" wasn't taking out the dash, that's the only reason it's there now. Also, I originally had 4 "vbBack" {Chr(8)} in the replacing portion but have changed it around to try to get rid of that final character.

    How do I get it so it won't send the dash {or whatever is chosen as the trigger symbol}?

    Also, if I put a msgbox in that section then it doesn't put in the trigger character.
    --> MsgBox("")
    So is there a way to spoof a message box or something similar? I don't want to have to click "Okay" on the message box every time I use the hotkeys. I've tried sleep {for 100 & 500} but it didn't work.

    Any help in this would be appreciated!

    Peace to you and yours,
    Matthew "Dra'Gon" Stohler
Working...