Espero su ayuda

Saludos y Pròspero Año Nuevo (d)
Escrito 30 diciembre 2009 - 08:27
Escrito 30 diciembre 2009 - 08:32
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 ?
Salud OS
Escrito 30 diciembre 2009 - 08:39
Escrito 30 diciembre 2009 - 08:42
¿ Que tecla es la que deseas capturar ?
Salud OS
Escrito 30 diciembre 2009 - 09:01
keybd_event(VK_F5,$74,KEYEVENTF_EXTENDEDKEY, 0);
Escrito 30 diciembre 2009 - 09:57
Ah vaya, ¿ y si intentas hacer esto ?
delphi
keybd_event(VK_F5,$74,KEYEVENTF_EXTENDEDKEY, 0);
Salud OS
Escrito 31 diciembre 2009 - 04:06
Escrito 31 diciembre 2009 - 06:52
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;
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
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;