Версия для печати темы

Нажмите сюда для просмотра этой темы в оригинальном формате

WinCity.Ru _ Программирование _ Перехват клавиш

Автор: the_dark_angel Вторник, 23 Декабря 2003, 12:18

Подскажите, пожалуйста, как в Delphi можно перехватить коды клавиш, нажатых в других окнах?

Автор: mokc0der Среда, 24 Декабря 2003, 2:39

ставишь хук

Автор: the_dark_angel Среда, 24 Декабря 2003, 9:25

А как это сделать?

Автор: mokc0der Четверг, 25 Декабря 2003, 6:24

The SetWindowsHookEx function installs an application-defined hook procedure into a hook chain. An application installs a hook procedure to monitor the system for certain types of events. A hook procedure can monitor events associated either with a specific thread or with all threads in the system. This function supersedes the SetWindowsHook function.

HHOOK SetWindowsHookEx(

int idHook, // type of hook to install
HOOKPROC lpfn, // address of hook procedure
HINSTANCE hMod, // handle of application instance
DWORD dwThreadId // identity of thread to install hook for
);


Parameters

idHook

Specifies the type of hook procedure to be installed. This parameter can be one of the following values:

Value Description
WH_KEYBOARD Installs a hook procedure that monitors keystroke messages. For more information, see the KeyboardProc hook procedure.


lpfn

Points to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a dynamic-link library (DLL). Otherwise, lpfn can point to a hook procedure in the code associated with the current process.

hMod

Identifies the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.

dwThreadId

Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads.



Return Values

If the function succeeds, the return value is the handle of the hook procedure.
If the function fails, the return value is NULL.

Remarks

An error may occur if the hMod parameter is NULL and the dwThreadId parameter is zero or specifies the identifier of a thread created by another process.
Chaining to the next hook procedure (that is, calling the CallNextHookEx function) is optional. An application or library can call the next hook procedure either before or after any processing in its own hook procedure. Although chaining to the next hook is optional, it is highly recommended; otherwise, the other applications that have installed hooks will not receive hook notifications and may behave incorrectly as a result.

Before terminating, an application must call the UnhookWindowsHookEx function to free system resources associated with the hook.
The scope of a hook depends on the hook type. Some hooks can be set only with system scope; others can also be set for only a specific thread, as shown in the following list:

P.S. научитесь пользоватся справкой от Delphi!

Автор: the_dark_angel Пятница, 26 Декабря 2003, 13:22

Я не силён в английском, но спасибо.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)