• Welcome to Valhalla Legends Archive.
 

VB(HELP) -GetAsyncKeyState

Started by MrRaza, March 16, 2003, 02:24 PM

Previous topic - Next topic

MrRaza

I have an instant messenger program that sends data from the client to the server but i manually have to click a textbox named, Send. I want to send data by just hitting the 'Enter' key. I've got some idea where to start namely,

GetAsyncKeyState
GetActiveWindow


Some more help would be greatly appreciated.

haZe

#1
Show me the code that runs when you click the send thing. I'll fix it to hit the enter key..
+hint: keyascii = 13 for enter+

MrRaza

#2
I know keyascii = 13 for enter, im looking at code from pscode.com, im trying as hard as i can to figure it out myself so give me a day or two..

MrRaza

Alright, so far i added a timer to my form set the interval to 1 millisecond. I also added a module that has the following code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Im assuming that's all I need.

Now back to the main form.

You have to also declare GetAsyncKeyState on your form.
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
I added the following code to the Private Sub Timer1_Timer() function.
Private Sub Timer1_Timer()
    
If Winsock1.State = sckConnected And KeyResult = GetAsyncKeyState(13) Then
        Winsock1.SendData txtSend.Text
        AddChat vbWhite, "<" & sUsername & ">" & _
                         vbGreen, txtSend.Text
End If
If Winsock1.State = sckClosed Then
    Timer1.Enabled = False
End If
End Sub

This checks to see if the enter key has been hit, if it does get hit, then it sends the data.

Any ideas on how to improve this code are welcome. :)

Noodlez

#4
that is so pointless, just go to the keypress event of your text box and check if keyascii = 13, i can't really tell what your talking about.. but if you mean another program, then subclass that textbox and look for char 13 then send the WM_CLICK message on the send button

haZe


Private Sub txtSend_KeyPress(KeyAscii as Integer)
    
If Winsock1.State = sckConnected And KeyAscii = 13 Then        
Winsock1.SendData txtSend.Text
        AddChat vbWhite, "<" & sUsername & ">" & _
                         vbGreen, txtSend.Text
End If
If Winsock1.State = sckClosed Then
    Timer1.Enabled = False
txtSend.Text = ""
End If
End Sub
[/color]
Your code with keyascii.
$$$$$$$$$$$$$$$$

Grok

#6
If this is your program, set the 'Default' property of the Send button to True.  When user hits enter, Send will be clicked.

Noodlez

#7
haze, you should first check if keyascii = 13 then check if the socket is connected with another if

dxoigmn

#8
You should also use symbolic constants, as many have said before.  vbKeyReturn.

MrRaza@school

#9
QuoteIf this is your program, set the 'Default' property of the Send button to True.  When user hits enter, Send will be clicked.

Yes, it is my program along with a classmates' at school. We are working on an instant messenger for a school project. Thanks for all your help btw.