Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Yegg on November 09, 2004, 03:20 PM

Title: KeyPress
Post by: Yegg on November 09, 2004, 03:20 PM
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?

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


(also, how can i find out the ascii number for all the letters and numbers?)
Title: Re: KeyPress
Post by: The-FooL on November 09, 2004, 03:23 PM
Why are you comparing KeyAscii to a string?
Title: Re: KeyPress
Post by: Yegg on November 09, 2004, 03:25 PM
hmm, well i've always done keypress this way and its worked fine. i just dont c how that should make a difference.
Title: Re: KeyPress
Post by: Stealth on November 09, 2004, 03:35 PM
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.
Title: Re: KeyPress
Post by: Yegg on November 09, 2004, 03:38 PM
ok now, i have the following code and it does the same thing as before.

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


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?
Title: Re: KeyPress
Post by: UserLoser. on November 09, 2004, 03:46 PM
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"?
Title: Re: KeyPress
Post by: Yegg on November 09, 2004, 03:48 PM
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?


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
Title: Re: KeyPress
Post by: Dyndrilliac on November 09, 2004, 05:50 PM
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))"
Title: Re: KeyPress
Post by: Newby on November 09, 2004, 05:52 PM
Quote from: Stealth on November 09, 2004, 03:35 PM
It forces your computer to do more thinking, wasting (albeit a minute amount of) time and clock cycles.
If you're so worried about losing that many clock cycles, you wouldn't be programming in Visual Basic. ;)
Title: Re: KeyPress
Post by: hismajesty on November 09, 2004, 05:58 PM
Quote2) What's the point in doing "KeyAscii = 0"?

To stop the computer from beeping.
Title: Re: KeyPress
Post by: Yegg on November 13, 2004, 11:21 AM
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.

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

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?
Title: Re: KeyPress
Post by: Warrior on November 13, 2004, 11:31 AM
why the hell do you have a set focus? If you already pressed enter woudlnt you still be in focus?
Title: Re: KeyPress
Post by: Yegg on November 13, 2004, 11:32 AM
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.
Title: Re: KeyPress
Post by: Dyndrilliac on November 13, 2004, 11:41 AM
Quote from: Yegg on November 13, 2004, 11:21 AM
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.

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


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?

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

Do: if keyascii = vbkeyreturnandkeyascii = 0

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

Title: Re: KeyPress
Post by: Warrior on November 13, 2004, 02:28 PM
/me wonders how in the hell he made a Bot
Title: Re: KeyPress
Post by: Dyndrilliac on November 13, 2004, 05:25 PM
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).

Title: Re: KeyPress
Post by: Yegg on November 13, 2004, 07:16 PM
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.
Title: Re: KeyPress
Post by: TheMinistered on November 14, 2004, 01:11 PM

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


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!
Title: Re: KeyPress
Post by: The-FooL on November 14, 2004, 08:54 PM
Quote from: Yegg on November 13, 2004, 07:16 PM
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.

Try using keydown instead?
Title: Re: KeyPress
Post by: Yegg on November 17, 2004, 02:11 PM
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.
Title: Re: KeyPress
Post by: LivedKrad on November 18, 2004, 07:10 AM
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.