Valhalla Legends Forums Archive | Visual Basic Programming | KeyPress

AuthorMessageTime
Yegg
im not sur y but my bots txtSend_KeyPress stopped working, whenever i hit enter to send a message it does absolutely nothing, it doesn't send and it doesn't get an error. take a look at the following code is there something wrong with it?

[code]Private Sub txtSend_KeyPress(KeyAscii As Integer)
    If KeyAscii = "13" Then
        If Len(Form1.txtSend.Text) >= 1 Then
        pbuffer.InsertNTString Form1.txtSend.Text
        pbuffer.sendPacket &HE
        txtSend.Text = ""
        KeyAscii = "0"
        End If
    End If
End Sub[/code]

(also, how can i find out the ascii number for all the letters and numbers?)
November 9, 2004, 9:20 PM
The-FooL
Why are you comparing KeyAscii to a string?
November 9, 2004, 9:23 PM
Yegg
hmm, well i've always done keypress this way and its worked fine. i just dont c how that should make a difference.
November 9, 2004, 9:25 PM
Stealth
KeyAscii is a numeric value. There's no reason to treat it as a string literal, which is exactly the result of putting quotes around it. It forces your computer to do more thinking, wasting (albeit a minute amount of) time and clock cycles.
November 9, 2004, 9:35 PM
Yegg
ok now, i have the following code and it does the same thing as before.

[code]Private Sub txtSend_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If Len(Form1.txtSend.Text) >= 1 Then
        pbuffer.InsertNTString Form1.txtSend.Text
        pbuffer.SendPacket &HE
        Form1.txtSend.Text = ""
        KeyAscii = 0
        End If
    End If
End Sub[/code]

i dont get y this isn't working when the exact same code works on my other bot. is it possinble that im missing something in PacketBuffer.cls?
November 9, 2004, 9:38 PM
UserLoser.
It looks fine to me.  My guess is you're thinking the Battle.net server is supposed to echo back to you your own chat messages like any other sent a chat message, well, it doesn't.  What happens if you try sending "/time"?
November 9, 2004, 9:46 PM
Yegg
when i do /time the bot doesn't do ne thing because it isn't sending messages 2 battle.net. it seems a lot like its not reading the ascii character. is the following code in my packetbuffer correct?


[code]Public Function InsertNTString(data As String)
    Buffer = Buffer & data & Chr(0)
End Function

Public Function SendPacket(PacketID As Byte)
If Form1.wsBNET.State <> sckConnected Then: Exit Function
    Form1.wsBNET.SendData Chr(&HFF) & Chr(PacketID) & MakeWORD(Len(Buffer) + 4) & Buffer
    Clear
End Function[/code]
November 9, 2004, 9:48 PM
Dyndrilliac
Some general pointers, may or may not help

1) Use constants. (I.E., 13 becomes vbKeyReturn)

2) What's the point in doing "KeyAscii = 0"?

3) You're not doing a check to make sure your connected before inserting a null terminated string which could probably cause wierd shit to happen.

4) Make sure the text curso is in the text box at the time you press enter and the object is "In Focus".

5) Instead of checking the length of the string being sent, do "if not string = vbNullstring or string = space$(len(string))"
November 9, 2004, 11:50 PM
Newby
[quote author=Stealth link=topic=9484.msg88107#msg88107 date=1100036107]
It forces your computer to do more thinking, wasting (albeit a minute amount of) time and clock cycles.
[/quote]
If you're so worried about losing that many clock cycles, you wouldn't be programming in Visual Basic. ;)
November 9, 2004, 11:52 PM
hismajesty
[quote]2) What's the point in doing "KeyAscii = 0"?[/quote]

To stop the computer from beeping.
November 9, 2004, 11:58 PM
Yegg
ok, now im really confused, i read wut u told me to do dyndrillaid (cant spell ur name unless i look) and heres the following code.

[code]Private Sub txtSend_KeyPress(KeyAscii As Integer)
txtSend.SetFocus
    If KeyAscii = "13" Then
            pbuffer.InsertNTString txtSend.Text
            pbuffer.SendPacket &HE
            txtSend.Text = ""
            KeyAscii = "0"
    End If
End Sub[/code]
im a lil confused with this, it only sends the message when i hit enter and shift at the same time? even when i dont use the quotes around 13 and 0 it still functions the same way. how do i fix this?
November 13, 2004, 5:21 PM
Quarantine
why the hell do you have a set focus? If you already pressed enter woudlnt you still be in focus?
November 13, 2004, 5:31 PM
Yegg
im not sur y i have setfocus, i wus jus trying some stuff. apparently it didn't help either. also, i updated my post as u sent ur message. ok, i took out setfocus, it functions the same way still.
November 13, 2004, 5:32 PM
Dyndrilliac
[quote author=Yegg link=topic=9484.msg88750#msg88750 date=1100366511]
ok, now im really confused, i read wut u told me to do dyndrillaid (cant spell ur name unless i look) and heres the following code.

[code]Private Sub txtSend_KeyPress(KeyAscii As Integer)
txtSend.SetFocus
    If KeyAscii = "13" Then
            pbuffer.InsertNTString txtSend.Text
            pbuffer.SendPacket &HE
            txtSend.Text = ""
            KeyAscii = "0"
    End If
End Sub[/code]

im a lil confused with this, it only sends the message when i hit enter and shift at the same time? even when i dont use the quotes around 13 and 0 it still functions the same way. how do i fix this?
[/quote]

The value of KeyAscii is an integer. Stop comparing-it-with/assigning-it a string (KeyAscii = "0" & If KeyAscii = "13").

Do: [code]if keyascii = vbkeyreturn[/code]and[code]keyascii = 0[/code]

Do the set focus when the Text Box is not in focus,

November 13, 2004, 5:41 PM
Quarantine
[me=Warrior]wonders how in the hell he made a Bot[/me]
November 13, 2004, 8:28 PM
Dyndrilliac
Something I just noticed.

You do realize you have to add your own message to the chat window, since sending a message does not call the UserTalk Event, correct? The message is being sent but you aren't adding the text you sent to your RichTextBox (If that's what you're using).

November 13, 2004, 11:25 PM
Yegg
i know this! and im not worried about adding the chat yet, i just couldn't get the bot to send message by pressing enter, while im using the same code on another bot of mine and it works. and i have "13 instead of 13. this bot im working on now just wont send message by pressing enter, instead it will send them if i press shift and enter at the same time.
November 14, 2004, 1:16 AM
TheMinistered
[code]
Private Sub txtSend_KeyPress(KeyAscii As Integer)
   
    If (KeyAscii = vbKeyReturn) Then
        If (LenB(txtSend.Text) <> 0) Then
            pbuffer.InsertNTString txtSend.Text
            pbuffer.sendPacket &HE
           
            txtSend.Text = vbNullString
           
            KeyAscii = 0
        End If
    End If
   
End Sub
[/code]

This code should work correctly, if it still isn't sending your message to battle.net-- then you should be slapped.  Why?  Because if it still isn't then it's OBVIOUSLY a problem with your packet buffer!
November 14, 2004, 7:11 PM
The-FooL
[quote author=Yegg link=topic=9484.msg88792#msg88792 date=1100394981]
i know this! and im not worried about adding the chat yet, i just couldn't get the bot to send message by pressing enter, while im using the same code on another bot of mine and it works. and i have "13 instead of 13. this bot im working on now just wont send message by pressing enter, instead it will send them if i press shift and enter at the same time.
[/quote]

Try using keydown instead?
November 15, 2004, 2:54 AM
Yegg
ok, sorry for not reading this thread in a while but i found out that theres nothing wrong with the packetbuffer, it wus the keypress part, so ima go with the code TheMinistered showed and see how this works out, if it doesn't work then.......i think i've tried everything.
November 17, 2004, 8:11 PM
LivedKrad
Ahh *makes note of TM's use of constants*. I love constants, they are so much prettier than their integer/string counterparts! Assuming the functions for adding items into the buffer match what TM has, it should work fine. Yet, if you have used people's code and not taken into account that there are function name inconsistencies, (ie: NOT THE SAME FUNCTION), then you should be slapped.
November 18, 2004, 1:10 PM

Search