Ir al contenido


Foto

Enviar tecla con PostMessage a ventana de un proceso


  • Por favor identifícate para responder
9 respuestas en este tema

#1 BrainDeath

BrainDeath

    Member

  • Miembros
  • PipPip
  • 28 mensajes

Escrito 30 diciembre 2009 - 08:27

Bueno quiero mandar la pulsacion de una tecla con PostMessage a una ventana que ocupa toda la pantalla pero casi no encuentro informacion que me sirva ps alguien tiene alguna idea de como hacerlo

Espero su ayuda  *-)

Saludos y Pròspero Año Nuevo  (d)
  • 0

#2 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 30 diciembre 2009 - 08:32

Hola

¿ Y no te sirven los eventos OnKeyPress, OnKeyDown de la forma ?

Me imagino que al ocupar toda la pantalla siempre tiene el foco, ¿ o me equivoco ?

Imagen Enviada

Salud OS


  • 0

#3 BrainDeath

BrainDeath

    Member

  • Miembros
  • PipPip
  • 28 mensajes

Escrito 30 diciembre 2009 - 08:36

Hola

¿ Y no te sirven los eventos OnKeyPress, OnKeyDown de la forma ?

Me imagino que al ocupar toda la pantalla siempre tiene el foco, ¿ o me equivoco ?

Imagen Enviada

Salud OS


Pero es para la ventana de un proceso que ocupa toda la pantalla pero usando la api keybd_event no detecta el pulsado de la tecla y ps creo que la unica manera que debe funcionar es mandando  la tecla


  • 0

#4 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 30 diciembre 2009 - 08:39

¿ Que tecla es la que deseas capturar ?

Salud OS
  • 0

#5 BrainDeath

BrainDeath

    Member

  • Miembros
  • PipPip
  • 28 mensajes

Escrito 30 diciembre 2009 - 08:42

¿ Que tecla es la que deseas capturar ?

Salud OS


F5  :embarrassed:
  • 0

#6 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 30 diciembre 2009 - 09:01

Ah vaya, ¿ y si intentas hacer esto ?



delphi
  1.   keybd_event(VK_F5,$74,KEYEVENTF_EXTENDEDKEY, 0);



Salud OS
  • 0

#7 BrainDeath

BrainDeath

    Member

  • Miembros
  • PipPip
  • 28 mensajes

Escrito 30 diciembre 2009 - 09:57

Ah vaya, ¿ y si intentas hacer esto ?



delphi
  1.   keybd_event(VK_F5,$74,KEYEVENTF_EXTENDEDKEY, 0);



Salud OS


Aun sigue sin funcionar funciona  :s eps creo que usando PostMessage debe funcionar
  • 0

#8 Marc

Marc

    Advanced Member

  • Moderadores
  • PipPipPip
  • 1.484 mensajes
  • LocationMallorca

Escrito 31 diciembre 2009 - 04:06

Hola, ¿ que error tienes con PostMessage ?, prueba esta llamada para enviar la pulsación por código :

PostMessage( GetParentForm(Self).Handle, WM_NEXTDLGCTL,0,0 );

Cambia WM_NEXTDLGCTL por el código de la tecla que quieras enviar (WM_NEXTDLGCTL es el tabulador, para forzar el salto al siguiente control).
  • 0

#9 seoane

seoane

    Advanced Member

  • Administrador
  • 1.259 mensajes
  • LocationEspaña

Escrito 31 diciembre 2009 - 06:52

La funcion keybd_event funciona mal con algunos programas, especialmente los juegos.

Prueba con la funcion SendInput, que suele funcionar cuando la otra falla.



delphi
  1. procedure SendKey(Code: Cardinal; KeyUp: Boolean);
  2. var
  3.   Input: TInput;
  4. begin
  5.   FillChar(Input,Sizeof(Input),0);
  6.   Input.Itype:= INPUT_KEYBOARD;
  7.   Input.ki.wScan:= MapVirtualKey(Code,0);
  8.   if KeyUp then
  9.     Input.ki.dwFlags:= KEYEVENTF_SCANCODE or KEYEVENTF_KEYUP
  10.   else
  11.     Input.ki.dwFlags:= KEYEVENTF_SCANCODE;
  12.   SendInput(1,Input,Sizeof(TInput));
  13. end;
  14.  
  15. // Por ejemplo
  16. SendKey(VK_F5,FALSE);
  17. Sleep(200);
  18. SendKey(VK_F5,TRUE);



Aqui te dejo un ejemplo que envía la tecla F5 cuando se pulsa el botón derecho del ratón.


delphi
  1. const
  2.   WH_MOUSE_LL = 14;
  3.   KEYEVENTF_SCANCODE = $08;
  4.  
  5. var
  6.   Hook: HHook;
  7.  
  8. // Esta funcion es la que envia la tecla
  9. procedure SendKey(Code: Cardinal; KeyUp: Boolean);
  10. var
  11.   Input: TInput;
  12. begin
  13.   FillChar(Input,Sizeof(Input),0);
  14.   Input.Itype:= INPUT_KEYBOARD;
  15.   Input.ki.wScan:= MapVirtualKey(Code,0);
  16.   if KeyUp then
  17.     Input.ki.dwFlags:= KEYEVENTF_SCANCODE or KEYEVENTF_KEYUP
  18.   else
  19.     Input.ki.dwFlags:= KEYEVENTF_SCANCODE;
  20.   SendInput(1,Input,Sizeof(TInput));
  21. end;
  22.  
  23. function MouseProc(Code: Integer; WParam, LParam: DWORD): LRESULT; stdcall;
  24. begin
  25.   if Code = HC_ACTION then
  26.   begin
  27.     if WParam = WM_RBUTTONDOWN then
  28.       SendKey(VK_F5,FALSE)
  29.     else
  30.     if WParam = WM_RBUTTONUP then
  31.       SendKey(VK_F5,TRUE);
  32.   end;
  33.   Result := CallNextHookEx(Hook, Code, WParam, LParam);
  34. end;
  35.  
  36. procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  37. begin
  38.   // Quitamos el hook
  39.   if Hook <> 0 then UnhookWindowsHookEx(Hook);
  40. end;
  41.  
  42. procedure TForm1.FormCreate(Sender: TObject);
  43. begin
  44.   // Arrancamos el hook, por ejemplo al crear el formulario
  45.   Hook := SetWindowsHookEx(WH_MOUSE_LL, @MouseProc, HInstance, 0);
  46. end;


  • 0

#10 BrainDeath

BrainDeath

    Member

  • Miembros
  • PipPip
  • 28 mensajes

Escrito 31 diciembre 2009 - 12:48

La funcion keybd_event funciona mal con algunos programas, especialmente los juegos.

Prueba con la funcion SendInput, que suele funcionar cuando la otra falla.



delphi
  1. procedure SendKey(Code: Cardinal; KeyUp: Boolean);
  2. var
  3.   Input: TInput;
  4. begin
  5.   FillChar(Input,Sizeof(Input),0);
  6.   Input.Itype:= INPUT_KEYBOARD;
  7.   Input.ki.wScan:= MapVirtualKey(Code,0);
  8.   if KeyUp then
  9.     Input.ki.dwFlags:= KEYEVENTF_SCANCODE or KEYEVENTF_KEYUP
  10.   else
  11.     Input.ki.dwFlags:= KEYEVENTF_SCANCODE;
  12.   SendInput(1,Input,Sizeof(TInput));
  13. end;
  14.  
  15. // Por ejemplo
  16. SendKey(VK_F5,FALSE);
  17. Sleep(200);
  18. SendKey(VK_F5,TRUE);



Aqui te dejo un ejemplo que envía la tecla F5 cuando se pulsa el botón derecho del ratón.


delphi
  1. const
  2.   WH_MOUSE_LL = 14;
  3.   KEYEVENTF_SCANCODE = $08;
  4.  
  5. var
  6.   Hook: HHook;
  7.  
  8. // Esta funcion es la que envia la tecla
  9. procedure SendKey(Code: Cardinal; KeyUp: Boolean);
  10. var
  11.   Input: TInput;
  12. begin
  13.   FillChar(Input,Sizeof(Input),0);
  14.   Input.Itype:= INPUT_KEYBOARD;
  15.   Input.ki.wScan:= MapVirtualKey(Code,0);
  16.   if KeyUp then
  17.     Input.ki.dwFlags:= KEYEVENTF_SCANCODE or KEYEVENTF_KEYUP
  18.   else
  19.     Input.ki.dwFlags:= KEYEVENTF_SCANCODE;
  20.   SendInput(1,Input,Sizeof(TInput));
  21. end;
  22.  
  23. function MouseProc(Code: Integer; WParam, LParam: DWORD): LRESULT; stdcall;
  24. begin
  25.   if Code = HC_ACTION then
  26.   begin
  27.     if WParam = WM_RBUTTONDOWN then
  28.       SendKey(VK_F5,FALSE)
  29.     else
  30.     if WParam = WM_RBUTTONUP then
  31.       SendKey(VK_F5,TRUE);
  32.   end;
  33.   Result := CallNextHookEx(Hook, Code, WParam, LParam);
  34. end;
  35.  
  36. procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  37. begin
  38.   // Quitamos el hook
  39.   if Hook <> 0 then UnhookWindowsHookEx(Hook);
  40. end;
  41.  
  42. procedure TForm1.FormCreate(Sender: TObject);
  43. begin
  44.   // Arrancamos el hook, por ejemplo al crear el formulario
  45.   Hook := SetWindowsHookEx(WH_MOUSE_LL, @MouseProc, HInstance, 0);
  46. end;



Exactamente quiero enviar la tecla a la ventana de un juego y creo que la unica manera que sirva es enviando un hook del la tecla al handle del juego  hay alguna manera de hacer el hook enviando la tecla al handle?  :s

Saludos y Pròspero Año Nuevo
  • 0




IP.Board spam blocked by CleanTalk.