Hook Clavier

Résolu
olixelle Messages postés 506 Date d'inscription vendredi 30 juillet 2004 Statut Membre Dernière intervention 3 mars 2008 - 22 sept. 2006 à 09:30
cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 - 22 sept. 2006 à 10:02
Bonjour,

j'ai implémenté dans mon application un hook clavier afin qu'elle puisse etre piloté via le clavier.
Tout marche bien.

Cependant, si l'application n'est pas en foreground, le hook clavier est qd mm appelé.

Je souhaiterais que mon Hook intercepte les evenements clavier uniquement pour mon appli.

Voici le code que j'utilise:

Private
Declare
Function SetWindowsHookEx
Lib "user32" _

Alias "SetWindowsHookExA" (
ByVal idHook
As
Integer, _

ByVal lpfn
As KeyboardHookDelegate,
ByVal hmod
As
Integer, _

ByVal dwThreadId
As
Integer)
As
Integer
...

callback =

New KeyboardHookDelegate(
AddressOf KeyboardCallback)KeyboardHandle = SetWindowsHookEx(WH_KEYBOARD_LL, callback, Marshal.GetHINSTANCE([Assembly].GetExecutingAssembly.GetModules()(0)).ToInt32, 0)

D'apres ce code, j'ai l'impression de lui demander de ne gérer que les evt clavier pour mon appli( (GetExecutingAssembly))

Mais bon ca ne marche pas :(

Si vous avez une idée...

Merci :)

Rollerman

4 réponses

cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 40
22 sept. 2006 à 10:02
si tu est en net2005, GetCurrentThreadId n'est plus supporté.

Essaye peut-etre de remplacer AppDomain.CurrentDomain.GetCurrentThreadId()
par Thread.CurrentThread.ID

---- Sevyc64  (alias Casy) ----<hr size="2" width="100%" /># LE PARTAGE EST NOTRE FORCE #
3
cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 40
22 sept. 2006 à 09:38
D'après l'apiguide, pour limiter le hook à ton appli, je verrais plutot le troisème paramètre à NULL et par contre il faudrait mettre le ThreadID de ton appli dans le quatrième.

· 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.

---- Sevyc64  (alias Casy) ----<hr size="2" width="100%" /># LE PARTAGE EST NOTRE FORCE #
0
olixelle Messages postés 506 Date d'inscription vendredi 30 juillet 2004 Statut Membre Dernière intervention 3 mars 2008 2
22 sept. 2006 à 09:44
Salut Casy,

ben j'avais fait le test suivant:
KeyboardHandle = SetWindowsHookEx(WH_KEYBOARD_LL, callback, 0, AppDomain.CurrentDomain.GetCurrentThreadId())

Mais ca ne marche pas mieux :(

Rollerman
0
olixelle Messages postés 506 Date d'inscription vendredi 30 juillet 2004 Statut Membre Dernière intervention 3 mars 2008 2
22 sept. 2006 à 09:45
en fait ca ne marche pas du totu :(

Rollerman
0
Rejoignez-nous