Espero su ayuda

Saludos y Pròspero Año Nuevo (d)
Posted 30 December 2009 - 08:27 PM
Posted 30 December 2009 - 08:32 PM
Posted 30 December 2009 - 08:36 PM
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 ?
Salud OS
Posted 30 December 2009 - 08:39 PM
Posted 30 December 2009 - 08:42 PM
¿ Que tecla es la que deseas capturar ?
Salud OS
Posted 30 December 2009 - 09:01 PM
keybd_event(VK_F5,$74,KEYEVENTF_EXTENDEDKEY, 0);
Posted 30 December 2009 - 09:57 PM
Ah vaya, ¿ y si intentas hacer esto ?
delphi
keybd_event(VK_F5,$74,KEYEVENTF_EXTENDEDKEY, 0);
Salud OS
Posted 31 December 2009 - 04:06 AM
Posted 31 December 2009 - 06:52 AM
procedure SendKey(Code: Cardinal; KeyUp: Boolean); var Input: TInput; begin FillChar(Input,Sizeof(Input),0); Input.Itype:= INPUT_KEYBOARD; Input.ki.wScan:= MapVirtualKey(Code,0); if KeyUp then Input.ki.dwFlags:= KEYEVENTF_SCANCODE or KEYEVENTF_KEYUP else Input.ki.dwFlags:= KEYEVENTF_SCANCODE; SendInput(1,Input,Sizeof(TInput)); end; // Por ejemplo SendKey(VK_F5,FALSE); Sleep(200); SendKey(VK_F5,TRUE);
const WH_MOUSE_LL = 14; KEYEVENTF_SCANCODE = $08; var Hook: HHook; // Esta funcion es la que envia la tecla procedure SendKey(Code: Cardinal; KeyUp: Boolean); var Input: TInput; begin FillChar(Input,Sizeof(Input),0); Input.Itype:= INPUT_KEYBOARD; Input.ki.wScan:= MapVirtualKey(Code,0); if KeyUp then Input.ki.dwFlags:= KEYEVENTF_SCANCODE or KEYEVENTF_KEYUP else Input.ki.dwFlags:= KEYEVENTF_SCANCODE; SendInput(1,Input,Sizeof(TInput)); end; function MouseProc(Code: Integer; WParam, LParam: DWORD): LRESULT; stdcall; begin if Code = HC_ACTION then begin if WParam = WM_RBUTTONDOWN then SendKey(VK_F5,FALSE) else if WParam = WM_RBUTTONUP then SendKey(VK_F5,TRUE); end; Result := CallNextHookEx(Hook, Code, WParam, LParam); end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin // Quitamos el hook if Hook <> 0 then UnhookWindowsHookEx(Hook); end; procedure TForm1.FormCreate(Sender: TObject); begin // Arrancamos el hook, por ejemplo al crear el formulario Hook := SetWindowsHookEx(WH_MOUSE_LL, @MouseProc, HInstance, 0); end;
Posted 31 December 2009 - 12:48 PM
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
procedure SendKey(Code: Cardinal; KeyUp: Boolean); var Input: TInput; begin FillChar(Input,Sizeof(Input),0); Input.Itype:= INPUT_KEYBOARD; Input.ki.wScan:= MapVirtualKey(Code,0); if KeyUp then Input.ki.dwFlags:= KEYEVENTF_SCANCODE or KEYEVENTF_KEYUP else Input.ki.dwFlags:= KEYEVENTF_SCANCODE; SendInput(1,Input,Sizeof(TInput)); end; // Por ejemplo SendKey(VK_F5,FALSE); Sleep(200); 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
const WH_MOUSE_LL = 14; KEYEVENTF_SCANCODE = $08; var Hook: HHook; // Esta funcion es la que envia la tecla procedure SendKey(Code: Cardinal; KeyUp: Boolean); var Input: TInput; begin FillChar(Input,Sizeof(Input),0); Input.Itype:= INPUT_KEYBOARD; Input.ki.wScan:= MapVirtualKey(Code,0); if KeyUp then Input.ki.dwFlags:= KEYEVENTF_SCANCODE or KEYEVENTF_KEYUP else Input.ki.dwFlags:= KEYEVENTF_SCANCODE; SendInput(1,Input,Sizeof(TInput)); end; function MouseProc(Code: Integer; WParam, LParam: DWORD): LRESULT; stdcall; begin if Code = HC_ACTION then begin if WParam = WM_RBUTTONDOWN then SendKey(VK_F5,FALSE) else if WParam = WM_RBUTTONUP then SendKey(VK_F5,TRUE); end; Result := CallNextHookEx(Hook, Code, WParam, LParam); end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin // Quitamos el hook if Hook <> 0 then UnhookWindowsHookEx(Hook); end; procedure TForm1.FormCreate(Sender: TObject); begin // Arrancamos el hook, por ejemplo al crear el formulario Hook := SetWindowsHookEx(WH_MOUSE_LL, @MouseProc, HInstance, 0); end;