Ver Mensaje Individual
  #4 (permalink)  
Antiguo 17/06/2010, 14:01
Avatar de pkj
pkj
 
Fecha de Ingreso: julio-2006
Ubicación: Órbita sincrónica
Mensajes: 899
Antigüedad: 17 años, 9 meses
Puntos: 29
Respuesta: Ejecutar en segundo plano Vb6

Si quieres leer el teclado desde cualquier sitio tienes que usar algo como GetAsyncKeyState.

Algo asi:

Con un timer...

Código vb:
Ver original
  1. Option Explicit
  2. Private Const constKeyDown = -32767
  3.  
  4. Const MOUSEEVENTF_MOVE = &H1 '  movimiento del mouse
  5. Const MOUSEEVENTF_LEFTDOWN = &H2 '  botón izquierdo presionado
  6. Const MOUSEEVENTF_LEFTUP = &H4 '  botón izquierdo soltado
  7. Const MOUSEEVENTF_RIGHTDOWN = &H8 '  botón derecho presionado
  8. Const MOUSEEVENTF_RIGHTUP = &H10 '  botón derecho soltado
  9. Const MOUSEEVENTF_MIDDLEDOWN = &H20 '  botón central presionado
  10. Const MOUSEEVENTF_MIDDLEUP = &H40 ' botón central soltado
  11. Const MOUSEEVENTF_ABSOLUTE = &H8000 '  movimiento absoluto
  12.  
  13. Private Type POINTAPI
  14.     X As Long
  15.     Y As Long
  16. End Type
  17.  
  18. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
  19. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  20. Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
  21. Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
  22.  
  23. Private Sub Form_Load()
  24.   Timer1.Interval = 50
  25.   Timer1.Enabled = True
  26. End Sub
  27.  
  28. Private Sub Timer1_Timer()
  29.   Dim Point As POINTAPI
  30.   Static Levantar_L As Integer
  31.   Static Levantar_R As Integer
  32.  
  33.   If GetAsyncKeyState(40) <= constKeyDown Then
  34.     'MsgBox ("Abajo")
  35.    GetCursorPos Point
  36.     SetCursorPos Point.X, Point.Y + 10
  37.   End If
  38.  
  39.   If GetAsyncKeyState(38) <= constKeyDown Then
  40.     'MsgBox ("Arriba")
  41.    GetCursorPos Point
  42.     SetCursorPos Point.X, Point.Y - 10
  43.   End If
  44.  
  45.   If GetAsyncKeyState(37) <= constKeyDown Then
  46.     'MsgBox ("Izquierda")
  47.    GetCursorPos Point
  48.     SetCursorPos Point.X - 10, Point.Y
  49.   End If
  50.  
  51.   If GetAsyncKeyState(39) <= constKeyDown Then
  52.     'MsgBox ("Derecha")
  53.    GetCursorPos Point
  54.     SetCursorPos Point.X + 10, Point.Y
  55.   End If
  56.  
  57.   If GetAsyncKeyState(vbKeyZ) <= constKeyDown Then
  58.     If Levantar_L = 0 Then
  59.       mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_ABSOLUTE, 0, 0, 0, 0
  60.       Levantar_L = 1
  61.     End If
  62.   Else
  63.     If Levantar_L = 1 Then
  64.       mouse_event MOUSEEVENTF_LEFTUP Or MOUSEEVENTF_ABSOLUTE, 0, 0, 0, 0
  65.       Levantar_L = 0
  66.     End If
  67.     'MsgBox ("Z")
  68.  End If
  69.  
  70.   If GetAsyncKeyState(vbKeyX) = constKeyDown Then
  71.     If Levantar_R = 0 Then
  72.       mouse_event MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_ABSOLUTE, 0, 0, 0, 0
  73.       Levantar_R = 1
  74.     End If
  75.   Else
  76.     If Levantar_R = 1 Then
  77.       mouse_event MOUSEEVENTF_RIGHTUP Or MOUSEEVENTF_ABSOLUTE, 0, 0, 0, 0
  78.       Levantar_R = 0
  79.     End If
  80.     'MsgBox ("X")
  81.  End If
  82.  
  83. End Sub

Saludos

PD: Lo he editado para mejorarlo. Ahora funciona tambien en diagonal.
__________________
No hay preguntas tontas, solo gente estup..., ¡No!, ¿como era? No hay gente que pregunte a tontos... ¡Nooo!... ¡Vaya cabeza!

Última edición por pkj; 18/06/2010 a las 02:58 Razón: Mejora del código