Como Verán, lo que quiero hacer es que si en txtlog(label) el caption dice "Arriba" x ejemplo se presione VbKeyUp
Me dan Alguna idea o corregirme este código? (Se me Ocurrio a mi de esa Manera, pero no anda :S)
Código:
Const KEYEVENTF_KEYUP = &H2
Const KEYEVENTF_EXTENDEDKEY = &H1
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Sub Pulsar_Tecla(Tecla As Long)
Call keybd_event(Tecla, 0, 0, 0)
Call keybd_event(Tecla, 0, KEYEVENTF_KEYUP, 0)
End Sub
Private Sub AbajoT_Timer()
Call Pulsar_Tecla(vbKeyDown)
End Sub
Private Sub ArribaT_Timer()
Call Pulsar_Tecla(vbKeyUp)
End Sub
Private Sub bntListen_Click()
On Error GoTo errorSub
With Winsock1
.Close
.LocalPort = txtPort
.Listen
End With
Exit Sub
errorSub:
MsgBox "Error : " & Err.Description, vbCritical
End Sub
Private Sub bntSend_Click()
On Error GoTo errorSub
Winsock1.SendData txtSend
txtlog = txtlog & "Servidor : " & txtSend & vbCrLf
txtSend = ""
Exit Sub
errorSub:
MsgBox "Error : " & Err.Description
Winsock1_Close
End Sub
Private Sub DerechaT_Timer()
Call Pulsar_Tecla(vbKeyRight)
End Sub
Private Sub Form_Load()
Call bntListen_Click
AbajoT.Enabled = False
ArribaT.Enabled = False
DerechaT.Enabled = False
IzquierdaT.Enabled = False
If txtlog.Caption = "Abajo" Then
AbajoT.Enabled = True
ArribaT.Enabled = False
DerechaT.Enabled = False
IzquierdaT.Enabled = False
End If
If txtlog.Caption = "Arriba" Then
AbajoT.Enabled = False
ArribaT.Enabled = True
DerechaT.Enabled = False
IzquierdaT.Enabled = False
End If
If txtlog.Caption = "Derecha" Then
AbajoT.Enabled = False
ArribaT.Enabled = False
DerechaT.Enabled = True
IzquierdaT.Enabled = False
End If
If txtlog.Caption = "Izquierda" Then
AbajoT.Enabled = False
ArribaT.Enabled = False
DerechaT.Enabled = False
IzquierdaT.Enabled = True
End If
End Sub
Private Sub IzquierdaT_Timer()
Call Pulsar_Tecla(vbKeyLeft)
End Sub
Private Sub Winsock1_Close()
' Finaliza la conexión
Winsock1.Close
txtlog = txtlog & "*** Desconectado" & vbCrLf
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then
Winsock1.Close ' close
End If
Winsock1.Accept requestID
txtlog = "Cliente conectado. IP : " & _
Winsock1.RemoteHostIP & vbCrLf
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim dat As String
Winsock1.GetData dat, vbString
txtlog = dat & vbCrLf
End Sub
' cuando se produce un error lo envía
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Winsock1_Error(ByVal Number As Integer, _
Description As String, _
ByVal Scode As Long, _
ByVal Source As String, _
ByVal HelpFile As String, _
ByVal HelpContext As Long, _
CancelDisplay As Boolean)
txtlog = txtlog & "*** Error : " & Description & vbCrLf
Winsock1_Close
End Sub
Gracias de Antemano :)
en vez de usar too ese kodigo en timers yo pondria lo k haria dentro de este Sub
Private Sub Label1_Change()
'######Codigo a ejecutar#######
End Sub
y kon respekto a lo de detectar k tekla k pulso xk no usas
Private Declare Function GetAsyncKeyState Lib "user32.dll" ( ByVal vKey As Long) As Long
Hola, Gracias x responder, pero no se como se usa el Evento Change() porfavor me explican? o algun manual o algo.
Gracias :D
.
El evento change como su nombre lo indica hace y se ejecuta su acción cuando y solo cuando el .caption en el caso de los label cambia. en el caso de los botones es lo mismo, listbox (propiedad text), , textbox (propiedad text), etc..
Sangrientas Lunas!¡.
.
y la sintaxis como sería ?
Así?
Private Sub Label1_Change(.caption= Izquierda)
'######Codigo a ejecutar#######
End Sub
no tngo la menor idea yo :S
porque yo quiero q si el caption del label 1 diga Izquierda, se ejute la accion q yo quiero, no q se ejecute si el caption cambia, entienden?
jejeje ya te me tas confundiendo mucha mira aqui te hize un ejemplo
Private Sub Label1_Change()
If Label1.Caption = "izquierda" Then
MsgBox "Cambio a izquierda"
ElseIf Label1.Caption = "derecha" Then
MsgBox "Cambio a derecha"
End If
End Sub
GRACiAS!!!!! me sirvio de mucho :D
jejeje de naa amigo te estaba complicando la vida teniendo el codigo k posteaste arriba xD ... Salu2
jaja x poco creaba una dll o.O
Me surgio un problema :S
Yo puse asi miren (en el evento change de txtlog, qe es un label)
If txtlog.Caption = "Abajo" Then
AbajoT.Enabled = True
End if
Lo que AbajoT hace es:
Private Sub AbajoT_Timer()
SendKeys ("{DOWN}")
End Sub
Pero si dice caption de txtlog = Abajo , no pasa nada :S [Alguna solucion?]
Pusiste un intervalo al timer? xD
xk a mi eso me funciona bien U_U y asegurate d k txtlog es un label xk si fuera un textbox no tiene esa propiedad ..... mira prueba con esto
Private Sub Command1_Click()
Label1.Caption = "abajo"
End Sub
Private Sub Label1_Change()
If Label1.Caption = "abajo" Then
Timer1.Enabled = True
End If
End Sub
Private Sub Timer1_Timer()
SendKeys "{down}"
End Sub
y al timer dale un intervalo de 100 o si kieres mas komo kieras
smokes como t puedo agradecer? GRACIAS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Me ayudaste 2 veces en un post,, GROSO!!
d naa amio ;)