Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2005.01.23;
Скачать: CL | DM;

Вниз

Перехват нажатия кнопки.   Найти похожие ветки 

 
Lera   (2004-11-29 12:15) [0]

Скажите пожалуйста, как перехватить нажатие любой кнопки на клавиатуре вне зависимости от того, какая из форм приложения активна, либо в случае когда приложение свернуто.


 
MAINUSER ©   (2004-11-29 12:47) [1]

Используй HOOK для клавиатуры:
Вот тебе пример DLL файлы(надеюсь ты имеешь понятия на счёт DLL):

library Hook;
uses Windows, SysUtils;
const KF_UP_MY = $40000000;
var CurrentHook: HHook;
   KeyArray: array[0..19] of char;
   KeyArrayPtr: integer;
   CurFile:text;
function GlobalKeyBoardHook(code: integer; wParam: integer; lParam:
integer): longword; stdcall;
var
i:integer;
begin
 if code< 0 then
  begin
    result:=CallNextHookEx(CurrentHook,code,wParam,lparam);
    Exit;
  end;
 if ( (lParam and KF_UP_MY ) = 0) and (wParam> =65) and (wParam< =90) then
   begin
     KeyArray[KeyArrayPtr]:=char(wParam);
     KeyArrayPtr:=KeyArrayPtr+1;
     if KeyArrayPtr> 19 then
      begin
       for i:=0 to 19 do
       begin
         Assignfile(CurFile,"d:\log.txt");
         if fileexists("d:\log.txt")=false then rewrite(CurFile)
         else Append(CurFile);
         write(Curfile, KeyArray[i]);
         closefile(curfile);
       end;
       KeyArrayPtr:=0;
      end;
   end;
   CallNextHookEx(CurrentHook,code,wParam,lparam);
   result:=0;
end;
procedure SetupGlobalKeyBoardHook;
begin
 CurrentHook:=SetWindowsHookEx(WH_KEYBOARD, @GlobalKeyBoardHook,HInstance, 0);
 KeyArrayptr:=0;
end;
procedure unhook;
begin
 UnhookWindowshookEx(CurrentHook);
end;

exports
SetupGlobalKeyBoardHook, UnHook;
begin
end.

УДАЧИ!


 
mbIkola   (2004-12-03 14:22) [2]

А на 95 и 98 это не пройдет :(


 
midavik ©   (2004-12-03 15:09) [3]

Вот примерчик.

unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs;

type
 TForm1 = class(TForm)
   procedure FormCreate(Sender: TObject);
   procedure FormDestroy(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 protected
  procedure hotykey(var msg:TMessage); message WM_HOTKEY;
 end;

var
 Form1: TForm1;
 id,id2:Integer;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
id:=GlobalAddAtom("hotkey");
  RegisterHotKey(handle,id,mod_control,81);  //CTRL+R
id2:=GlobalAddAtom("hotkey2");
  RegisterHotKey(handle,id2,mod_control,82); //CTRL+Q
end;

procedure TForm1.hotykey(var msg:TMessage);
begin
if (msg.LParamLo=MOD_CONTROL) and (msg.LParamHi=81) then
 ShowMessage("Ctrl + Q was pushed !");
if (msg.LParamLo=MOD_CONTROL) and (msg.LParamHi=82) then
 ShowMessage("Ctrl + R was pushed !");
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(handle,id);
UnRegisterHotKey(handle,id2);
end;

end.




Страницы: 1 вся ветка

Текущий архив: 2005.01.23;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.03 c
4-1102268962
8ung
2004-12-05 20:49
2005.01.23
Две клавиауры


1-1104931809
Andrey, K
2005-01-05 16:30
2005.01.23
ListBox, cut and paste


3-1103623973
juice
2004-12-21 13:12
2005.01.23
Кодировки, русские символы


14-1104900231
ms
2005-01-05 07:43
2005.01.23
Про память (незнаю как еще назвать)...


3-1103529804
alex145
2004-12-20 11:03
2005.01.23
BDE глючит на полную