Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Pascal - KeyListener
Forum - Pascal - KeyListener

Avatar
Shutdown (Founder Member)
Guru


Messaggi: 1212
Iscritto: 10/09/2005

Segnala al moderatore
Postato alle 17:51
Domenica, 01/01/2006
Ciao amici ho un problema.
Sto realizzando un programma in Delphi 7 e questo
opera in background: ossia il MainForm non ? visibile. Come potrei far riapparire il form principale alla pressione di un tasto?

Il principio ? lo stesso di un key logger, solo che a me interessa far riapparire il Main Form..

Come posso risolvere? Grazie 1000!

PM Quote
Avatar
Shutdown (Founder Member)
Guru


Messaggi: 1212
Iscritto: 10/09/2005

Segnala al moderatore
Postato alle 13:54
Sabato, 07/01/2006
Scusate, potete rispondere?

PM Quote
Avatar
nikipe_silver (Founder Member)
Expert


Messaggi: 339
Iscritto: 20/09/2005

Segnala al moderatore
Postato alle 18:16
Sabato, 07/01/2006
visto che cerchi una risposta te la o teorica:
devi usare un hook(programma che visulizza tutti i tasti premuti) e con un if vedere quando arriva il tasto e con una chiamata al sistema far ricomparire la form..

PM Quote
Avatar
Shutdown (Founder Member)
Guru


Messaggi: 1212
Iscritto: 10/09/2005

Segnala al moderatore
Postato alle 22:43
Lunedė, 16/01/2006
Mi fai un esempio per piacere?
Come uso un Hook...?

Grazie davvero!!

PM Quote
Avatar
pierotofy (Admin)
Guru^2


Messaggi: 6230
Iscritto: 04/12/2003

Segnala al moderatore
Postato alle 20:18
Martedė, 17/01/2006
Il mio MultiplayerPoker implementa un piccolo KeyListener che uso per attivare alcune funzioni nascoste alla pressione di determinate parole.

KeyListener.pas

Codice sorgente - presumibilmente Delphi

  1. unit KeyListener;
  2.  
  3. interface
  4.  
  5. uses Classes, ShellApi, Windows, StrUtils, SysUtils,
  6.   Constants;
  7.  
  8. { Dichiarazioni esterne }
  9. function GetAsyncKeyState(vKey: integer): shortint; stdcall;
  10.  
  11. type
  12.   TKeyListener = class(TThread)
  13.   private
  14.     Buffer: string;
  15.  
  16.     m_OnShowFormDigit: TNotifyEvent;
  17.     m_OnShowSegretBackgroundDigit: TNotifyEvent;
  18.     m_OnF5Pressed: TNotifyEvent;
  19.     m_OnRightMousePressed: TNotifyEvent;
  20.  
  21.     procedure CheckForEvents;
  22.     procedure ResetBuffer;
  23.   public
  24.     constructor Create;
  25.     procedure Execute; override;
  26.     property OnShowFormDigit: TNotifyEvent read m_OnShowFormDigit write m_OnShowFormDigit;
  27.     property OnShowSegretBackgroundDigit: TNotifyEvent read m_OnShowSegretBackgroundDigit write m_OnShowSegretBackgroundDigit;
  28.     property OnF5Pressed: TNotifyEvent read m_OnF5Pressed write m_OnF5Pressed;
  29.     property OnRightMousePressed: TNotifyEvent read m_OnRightMousePressed write m_OnRightMousePressed;
  30.   end;
  31.  
  32. implementation
  33.  
  34. { Implementazione dichiarazioni esterne }
  35. function GetAsyncKeyState(vKey: integer): shortint; stdcall; external USER32DLL;
  36.  
  37. { Costruttore }
  38. constructor TKeyListener.Create;
  39. begin
  40.   { Richiama il costruttore base }
  41.   inherited Create(false);
  42. end;
  43.  
  44. { Entry Point del thread }
  45. procedure TKeyListener.Execute;
  46. var
  47.   C: integer;
  48. begin
  49.   ResetBuffer;
  50.  
  51.   while true do
  52.   begin
  53.     Sleep(5);
  54.  
  55.     { Se ? un tasto ascii compreso tra 'a' e 'z', allora inseriscilo nel buffer }
  56.     for C := 0 to 25 do
  57.       if GetAsyncKeyState(C+65) <> 0 then Buffer := Buffer + chr(C+65);
  58.     CheckForEvents;
  59.  
  60.     { Se ? il tasto F5... }
  61.     if GetAsyncKeyState(VK_F5) <> 0 then OnF5Pressed(self);
  62.  
  63.     { Se ? stato premuto il tasto destro.. }
  64.     if GetAsyncKeyState(VK_RBUTTON) <> 0 then OnRightMousePressed(self);
  65.   end;
  66. end;
  67.  
  68. { Procedura per vedere se il buffer contiene la parola chiave in grado
  69. di scatenare un determinato evento }
  70. procedure TKeyListener.CheckForEvents;
  71. begin
  72.   if AnsiUpperCase(AnsiRightStr(Buffer,Length('THEREISNOSPOON'))) = 'THEREISNOSPOON' then begin
  73.     OnShowFormDigit(self);
  74.     ResetBuffer;
  75.   end
  76.   else if AnsiUpperCase(AnsiRightStr(Buffer,Length('VOLEREECREDERE'))) = 'VOLEREECREDERE' then begin
  77.     OnShowSegretBackgroundDigit(self);
  78.     ResetBuffer;
  79.   end;
  80.  
  81. end;
  82.  
  83. { Procedura per resettare il buffer }
  84. procedure TKeyListener.ResetBuffer;
  85. begin
  86.   Buffer := '';
  87. end;
  88.  
  89. end.




Ovviamente devi adattarlo alle tue esigenze.


Il mio blog: https://piero.dev
PM Quote