Devier Caps Lock

Devier Caps Lock - Delphi/Pascal - Programmation

Marsh Posté le 08-09-2003 à 17:54:40    

:hello: Bonjour,
 
J'aurais besoin de savoir comment faire pour dévier la touche Caps Lock, par exemple sur le 'N', c'est-à-dire que lorsque l'utilisateur appuyerait sur Caps Lock, ce serait la lettre N qui s'inscrive au focus, et que le clavier ne passe pas en mode lettres capitales et inversément, quand on appuye sur N, c'est la fonction habituellement excercée par Caps Lock qui se mettrait en route...
 
J'ai déjà fais des recherches au près des Hooks clavier, et je suis arrivé au fait :  
 

Code :
  1. procedure TForm1.HookKeyboard1HookKeyDown(Sender: TObject; key: Word;
  2.   ExtendedKey, AltKey, PrevPressed: Boolean);
  3. begin
  4.   if Key = VK_CAPITAL then 'on inscrit le N';
  5. end;


 
Mais le Key n'influence en rien la touche appuyée, la variable est juste chargée de me dire quelle touche a été pressée ...
 
Quelqu'un aurait-il une idée à me faire parvenir ?

Reply

Marsh Posté le 08-09-2003 à 17:54:40   

Reply

Marsh Posté le 16-03-2004 à 21:57:18    

J'ai utilisé ce code là dans le passé qui te permet de hooker le clavier mais aussi de bloquer ou non les touches si tu le souhaites via la fonction setPassthru :  
 

Code :
  1. library toto;
  2. uses
  3.   Windows;
  4. {$R *.RES}
  5. type THookData=record
  6.        Handle,Msg,
  7.        hHook,Instances:Cardinal;
  8.        PassThru:Boolean;
  9.      end;
  10.      PHookData=^THookData;
  11. const
  12.    MutexName='UniqueMutexName';
  13.    MemShareName='UniqueMemShareName';
  14. var
  15.    MyMutex,
  16.    MemShare:Cardinal;
  17.    MyData:PHookData;
  18. function KbdHook(hCode,wParam:LongInt;lParam:LongInt):Longint;stdcall;
  19. begin
  20.      try
  21.        WaitForSingleObject(MyMutex,INFINITE);
  22.        if (MyData^.Msg<>0) and (hCode=HC_ACTION) then PostMessage(MyData^.Handle,MyData^.Msg,wParam,lParam);
  23.        if (MyData^.hHook <> 0) then begin
  24.           if(MyData^.PassThru = False) then Result:=-1
  25.            else Result:=CallNextHookEx(MyData^.hHook,hCode,wParam,lParam)
  26.        end else Result:=0
  27.      finally ReleaseMutex(MyMutex);
  28.      end;
  29. end;
  30. function hookKbd(Hwnd,MsgID:Cardinal):LongInt;stdcall;
  31. begin
  32.      try
  33.      WaitForSingleObject(MyMutex,INFINITE);
  34.      if MyData^.hHook<>0 then begin
  35.         Result:=0;ReleaseMutex(MyMutex);Exit;
  36.      end;
  37.      Result:=SetWindowsHookEx(WH_KEYBOARD,@KbdHook,HInstance,0);
  38.      if Result<>0 then begin
  39.         MyData^.hHook:=Result;
  40.         MyData^.Msg:=MsgID;
  41.         MyData^.Handle:=Hwnd;
  42.         MyData^.PassThru:=True;
  43.      end;
  44.      finally ReleaseMutex(MyMutex);
  45.      end;
  46. end;
  47. function unHookKbd:Boolean;stdcall;
  48. begin
  49.      try
  50.       WaitForSingleObject(MyMutex,INFINITE);
  51.       Result:=True;
  52.       if MyData^.hHook=0 then begin
  53.          ReleaseMutex(MyMutex);Exit;
  54.       end;
  55.       Result:=UnhookWindowsHookEx(MyData^.hHook);
  56.       if Result=True then begin
  57.          MyData^.hHook:=0; MyData^.Msg:=0; MyData^.Handle:=0; MyData^.PassThru:=True;
  58.       end;
  59.      finally ReleaseMutex(MyMutex);
  60.      end;
  61. end;
  62. function isHooked:Boolean;stdcall;
  63. begin
  64.      WaitForSingleObject(MyMutex,INFINITE);
  65.      Result:=(MyData^.hHook<>0);
  66.      ReleaseMutex(MyMutex);
  67. end;
  68. function setPassthru(NewPassthru:Boolean):Boolean;stdcall;
  69. begin
  70.      WaitForSingleObject(MyMutex,INFINITE);
  71.      Result:=MyData^.Passthru;
  72.      MyData^.Passthru:=NewPassthru;
  73.      ReleaseMutex(MyMutex);
  74. end;
  75. function getPassthru:Boolean;stdcall;
  76. begin
  77.      WaitForSingleObject(MyMutex,INFINITE);
  78.      Result:=MyData^.Passthru;
  79.      ReleaseMutex(MyMutex);
  80. end;
  81. procedure EnterDLL;stdcall;
  82. var FirstInstance:Boolean;
  83. begin
  84.      MyMutex:=CreateMutex(nil,True,MutexName);
  85.      MemShare:=OpenFileMapping(FILE_MAP_ALL_ACCESS,False,PChar(MemShareName));
  86.      FirstInstance:=(MemShare=0);
  87.      if MemShare=0 then MemShare:=CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,0,SizeOf(THookData),MemShareName);
  88.      if MemShare<>0 then begin
  89.         MyData:=MapViewOfFile(MemShare,FILE_MAP_ALL_ACCESS,0,0,0);
  90.         if Firstinstance then with MyData^ do begin
  91.            Handle:=0;Msg:=0;hHook:=0;Instances:=0; PassThru:=True;
  92.         end;
  93.         MyData^.Instances:=MyData^.Instances+1;
  94.      end;
  95.      ReleaseMutex(MyMutex);
  96. end;
  97. procedure ExitDLL;stdcall;
  98. begin
  99.     try
  100.       WaitForSingleObject(MyMutex,INFINITE);
  101.       MyData^.Instances:=MyData^.Instances-1;
  102.       if (MyData^.Instances=0) then begin
  103.          UnmapViewOfFile(MyData);
  104.          CloseHandle(MemShare);
  105.          CloseHandle(MyMutex);
  106.        end;
  107.      finally ReleaseMutex(MyMutex);
  108.      end;
  109. end;
  110. procedure LibraryProc(Reason: Integer);
  111. begin
  112. case Reason of
  113.    DLL_PROCESS_DETACH:ExitDll;
  114.    DLL_PROCESS_ATTACH:EnterDll;
  115. end;
  116. end;
  117. exports hookKbd,unHookKbd,isHooked,getPassthru,setPassthru;
  118. //--------------------------------------------------------//
  119. begin
  120. EnterDLL;
  121. DllProc:=@LibraryProc;
  122. end.


 
Bon courage... :D

Reply

Marsh Posté le 17-03-2004 à 13:41:04    

D'où tu l'as déterré celui-là ? [:ddr5s5]

Reply

Marsh Posté le 17-03-2004 à 20:15:47    

:whistle:

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed