用程序控制CapLock, NumLock(50分)

  • 主题发起人 主题发起人 LeeChange
  • 开始时间 开始时间
var<br>&nbsp; Tkeys:TkeyBoardState;<br>Begin<br>&nbsp; GetkeyBoardState(Tkeys);<br>&nbsp; Tkeys[Vk_Capital]:=1;<br>&nbsp; Tkeys[Vk_Numlock]:=1;<br>&nbsp; SetkeyBoardState(Tkeys);<br>End;
 
好象有可以直接控制的,只有个印象,<br>好好找找。
 
接受答案了.
 
另一种方法:<br><br>procedure SetCapsLock(on: boolean); <br>begin <br>&nbsp; if on = (GetKeyState(VK_CAPITAL) = 0) then <br>&nbsp; begin <br>&nbsp; &nbsp; keybd_event(VK_CAPITAL, MapVirtualKey(VK_CAPITAL, 0), 0, 0); <br>&nbsp; &nbsp; keybd_event(VK_CAPITAL, MapVirtualKey(VK_CAPITAL, 0), KEYEVENTF_KEYUP, 0); <br>&nbsp; end; <br>end; <br>&nbsp; <br>procedure SetNumLock(on: boolean); <br>begin <br>&nbsp; if on = (GetKeyState(VK_CAPITAL) = 0) then <br>&nbsp; begin <br>&nbsp; &nbsp; keybd_event(VK_NUMLOCK, MapVirtualKey(VK_NUMLOCK, 0), <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; KEYEVENTF_EXTENDEDKEY, 0); <br>&nbsp; &nbsp; keybd_event(VK_NUMLOCK, MapVirtualKey(VK_NUMLOCK, 0), <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP, 0); <br>&nbsp; &nbsp; ShowMessage('ok'); <br>&nbsp; end; <br>end; <br>&nbsp; <br>procedure SetScroll(on: boolean); <br>begin <br>&nbsp; if on = (GetKeyState(VK_SCROLL) = 0) then <br>&nbsp; begin <br>&nbsp; &nbsp; keybd_event(VK_SCROLL, MapVirtualKey(VK_SCROLL, 0), 0, 0); <br>&nbsp; &nbsp; keybd_event(VK_SCROLL, MapVirtualKey(VK_SCROLL, 0), KEYEVENTF_KEYUP, 0); <br>&nbsp; end; <br>end; <br>&nbsp; <br>其中,numlock 应该跟其他一样,但我发现,灯并不变, <br>只有在用了 ShowMessage 以后才会正确变化, <br>谁能说说吗?
 
后退
顶部