Модераторы: Snowy, MetalFan, bems, Poseidon
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> hook в dll 
:(
    Опции темы
AlexeyShestchenko
Дата 19.2.2008, 17:59 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 59
Регистрация: 7.2.2008

Репутация: нет
Всего: нет



можно ли каким-нибудь образом осуществить перехват клавиш непосредственно в самой dll, т.е. только когда dll плагин загружен и нажать на определенное сочетание клавиш то происходили бы нужные мне операции находящиеся в dll плагине?
PM MAIL   Вверх
dumb
Дата 19.2.2008, 19:05 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


sceloglauxalbifacies
****


Профиль
Группа: Экс. модератор
Сообщений: 2929
Регистрация: 16.6.2006

Репутация: 3
Всего: 158



никаких проблем: ставишь хук(WH_KEYBOARD_LL) в DLL_PROCESS_ATTACH, в DLL_PROCESS_DETACH - снимаешь.
PM MAIL   Вверх
AlexeyShestchenko
Дата 22.2.2008, 02:45 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 59
Регистрация: 7.2.2008

Репутация: нет
Всего: нет



нашел тему где то на винграде и заделал под себя, но проблема в том что как только зажимаю ctrl+mouse1, то бесконечно много вылезает мессаг, мне надо чтобы одно нажатие, означало один вызов моего условия, помогите плз:

Код

library HookDLL;

uses
  SysUtils,
  Classes,
  Windows,
  Messages,
  dialogs;

const
  WM_SETFORE = WM_USER + 101;

var
  HKbdHook: HHook;
  MForm: HWND;

{$R *.res}

//------------------------------------------------------------------------------
// Hook
//------------------------------------------------------------------------------
function KeyboardProc(nCode: Integer; WP: wParam; LP: lParam): integer; stdcall;
begin
  Result := CallNextHookEx(HKbdHook, nCode, WP, LP);
  if nCode = HC_ACTION then
  begin
    //if (WP = 46) and (HI(GetKeyState(VK_CONTROL)) = 255) and (HI(GetKeyState(VK_MENU)) = 255) then
    if (HI(GetKeyState(VK_CONTROL)) = 255) and (HI(GetKeyState(VK_LBUTTON)) = 255) then
    begin
      ShowMessage('GGG');
     // SetforeGroundWindow(MFOrm);
      //SendMessage(MForm, WM_SETFORE, 0, 0);
    end;
  end;
end;

//------------------------------------------------------------------------------

procedure Hook(Flag: boolean; Handl: HWND); export; stdcall;
Begin
  MForm := Handl;
  if Flag then
    HKbdHook := SetWindowsHookEx(WH_KEYBOARD, @KeyboardProc, HInstance, 0)
  else begin
    UnhookWindowsHookEx(HKbdHook);
    HKbdHook := 0;
  end;
end;

exports
  Hook;

begin
end.


Код

interface

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

const
  WM_SETFORE = WM_USER + 101;

type
  TKeyboardProc = procedure (Flag: boolean; Handl: HWND); stdcall;
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
      protected
    procedure HotKeyReleased(var Message: TWmHotKey); message WM_HOTKEY;
    procedure WMSETFORE(var Message: TMsg); message WM_SETFORE;
  end;

var
  Form1: TForm1;
    HKey: integer;
  HKbdHook: integer;
  HookProc: TKeyboardProc;
  HookDLL: HModule;
  UniqKey: string;
  MsgId: integer;
implementation

{$R *.dfm}
//------------------------------------------------------------------------------
{ * * * * * * * * * * * * * * * * TfrmMain * * * * * * * * * * * * * * * * * * }
//------------------------------------------------------------------------------
// Îáðàáîò÷èê ãîðÿ÷åé êëàâèøè
//------------------------------------------------------------------------------
procedure Tform1.HotKeyReleased(var Message: TWmHotKey);
begin
  if Message.HotKey = HKey then
  begin
    SetForeGroundWindow(Handle);
    ShowMessage('Alt+Tab pressed!');
  end;
end;

//------------------------------------------------------------------------------

procedure Tform1.WMSETFORE(var Message: TMsg);
begin
  SetForeGroundWindow(Handle);
  ShowMessage('Ctrl+Alt+Del pressed!');
end;

//------------------------------------------------------------------------------

procedure Tform1.FormCreate(Sender: TObject);
begin
  HKey := GlobalAddAtom('MyHotKey');
  RegisterHotKey(Handle, HKey, MOD_ALT, 9);
  HookDLL := LoadLibrary('HookDLL.dll');
  @HookProc := getProcAddress(HookDLL, 'Hook');
  HookProc(True, Handle);
end;

//------------------------------------------------------------------------------




procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnRegisterHotKey(Handle, HKey);
  HookProc(False, Handle);
  FreeLibrary(HOOKDLL);
end;


PM MAIL   Вверх
MetalFan
Дата 22.2.2008, 10:54 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Аццкий Сотона
****


Профиль
Группа: Комодератор
Сообщений: 3815
Регистрация: 2.10.2006
Где: Moscow

Репутация: 22
Всего: 128



читай библию (aka MSDN).
зачем ты используешь GetKeyState???
Цитата(MSDN)
KeyboardProc Function
...
wParam
[in] Specifies the virtual-key code of the key that generated the keystroke message.
lParam
[in] Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag. For more information about the lParam parameter, see Keystroke Message Flags. This parameter can be one or more of the following values. 
0-15
Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the user's holding down the key.
16-23
Specifies the scan code. The value depends on the OEM.
24
Specifies whether the key is an extended key, such as a function key or a key on the numeric keypad. The value is 1 if the key is an extended key; otherwise, it is 0.
25-28
Reserved.
29
Specifies the context code. The value is 1 if the ALT key is down; otherwise, it is 0.
30
Specifies the previous key state. The value is 1 if the key is down before the message is sent; it is 0 if the key is up.
31
Specifies the transition state. The value is 0 if the key is being pressed and 1 if it is being released.



Это сообщение отредактировал(а) MetalFan - 22.2.2008, 10:55


--------------------
There are always someone smarter than you...
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "Delphi: Для новичков"
SnowyMetalFan
bemsPoseidon
Rrader

Запрещается!

1. Публиковать ссылки на вскрытые компоненты

2. Обсуждать взлом компонентов и делиться вскрытыми компонентами

  • Литературу по Дельфи обсуждаем здесь
  • Действия модераторов можно обсудить здесь
  • С просьбами о написании курсовой, реферата и т.п. обращаться сюда
  • Вопросы по реализации алгоритмов рассматриваются здесь
  • 90% ответов на свои вопросы можно найти в DRKB (Delphi Russian Knowledge Base) - крупнейшем в рунете сборнике материалов по Дельфи


Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, Snowy, MetalFan, bems, Poseidon, Rrader.

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Delphi: Для новичков | Следующая тема »


 




[ Время генерации скрипта: 0.0891 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.