Hook / Remplacement de touche

titoupit Messages postés 7 Date d'inscription lundi 22 août 2005 Statut Membre Dernière intervention 31 août 2005 - 26 août 2005 à 16:40
titoupit Messages postés 7 Date d'inscription lundi 22 août 2005 Statut Membre Dernière intervention 31 août 2005 - 31 août 2005 à 10:38
Bonjour,

J'intercepte le flux clavier avec un Hook et je bloque la touche "." du pavé numérique.

Mon problème c'est que j'aimerai remplacer cette touche par un "," ... mais lorsque je fait un sendkey ou keybd_event, mon hook intercepte le "," et me le recrache aprés celui que j'envoi "à la main" => Résultat je me retrouve avec ",,"

J'ai tout essayé mais j'y arrive tout simplement paaaaaaaaaassssss =>

****************************************************************

Public Function IsHooked(ByRef Hookstruct As KBDLLHOOKSTRUCT) As Integer
If (Hookstruct.vkCode = VK_DECIMAL) Then
Return Hookstruct.vkCode
End If
Return 0
End Function

****************************************************************


Public Function KeyboardCallback(ByVal Code As Integer, _
ByVal wParam As Integer, _
ByRef lParam As KBDLLHOOKSTRUCT) As Integer


If (Code = HC_ACTION) Then
If IsHooked(lParam) <> 0 Then
Return 1
End If
End If


Return CallNextHookEx(KeyboardHandle, Code, wParam, lParam)
End Function

****************************************************************


Public Delegate Function KeyboardHookDelegate( _
ByVal Code As Integer, _
ByVal wParam As Integer, _
ByRef lParam As KBDLLHOOKSTRUCT) As Integer

****************************************************************


<MarshalAs(UnmanagedType.FunctionPtr)> Private callback As KeyboardHookDelegate

****************************************************************
'Je lance donc la fonction qui suis =>


Public Sub HookKeyboard()
callback = New KeyboardHookDelegate(AddressOf KeyboardCallback)


KeyboardHandle = SetWindowsHookEx( _
WH_KEYBOARD_LL, callback, _
Marshal.GetHINSTANCE( _
[Assembly].GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
End Sub

****************************************************************

Quelqu'un aurai t'il une idée du "comment faire" ?

Merci!

6 réponses

ShareVB Messages postés 2676 Date d'inscription vendredi 28 juin 2002 Statut Membre Dernière intervention 13 janvier 2016 26
27 août 2005 à 15:21
salut,



je pense que tu remplaces simplement le code "." par "," dans vkCode et tu le passes à CallNextHookEx...

ShareVB
0
titoupit Messages postés 7 Date d'inscription lundi 22 août 2005 Statut Membre Dernière intervention 31 août 2005
29 août 2005 à 09:55
Déja tenté, mais ca marche pas
0
ShareVB Messages postés 2676 Date d'inscription vendredi 28 juin 2002 Statut Membre Dernière intervention 13 janvier 2016 26
30 août 2005 à 09:59
salut,



il faut aussi renvoyer 0 depuis la callback...

ShareVB
0
titoupit Messages postés 7 Date d'inscription lundi 22 août 2005 Statut Membre Dernière intervention 31 août 2005
30 août 2005 à 13:54
Bon j'ai pas mal galéré, mais j'ai finalement trouvé ça (c'est pas trés propre, mais au moins ça marche ^^):


Public Function KeyboardCallback(ByVal Code As Integer
, _


ByVal wParam As Integer
, ByRef lParam As KBDLLHOOKSTRUCT) As Integer


If (Code = HC_ACTION) Then


'Remplacement de touche "." par ","


If lParam.vkCode VK_DECIMAL And LastReplaced_DECIMAL "" Then


LastReplaced_DECIMAL = ","


Return
1


End If


If lParam.vkCode VK_DECIMAL And LastReplaced_DECIMAL "," Then


System.Windows.Forms.SendKeys.Send(",")


LastReplaced_DECIMAL = ""


Return
1


End If





Return
CallNextHookEx(KeyboardHandle, Code, wParam, lParam)


End Function
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
ShareVB Messages postés 2676 Date d'inscription vendredi 28 juin 2002 Statut Membre Dernière intervention 13 janvier 2016 26
30 août 2005 à 14:33
salut,



et en remplaçant le vkCode et en renvoyant RETURN 0...ca ne marche pas ?

ShareVB
0
titoupit Messages postés 7 Date d'inscription lundi 22 août 2005 Statut Membre Dernière intervention 31 août 2005
31 août 2005 à 10:38
Non, il me renvoie la touche initiale (comme si je ne changeais rien en fait!).

Attention, dans le code que j'ai passé il faut faire gaffe à l'état du caps lock (sinon on a un joli "?" qui sort qd on est en MAJ)
0
Rejoignez-nous