开发者

Can I turn the Capslock light on/off on individual keyboards?

开发者 https://www.devze.com 2023-01-12 03:25 出处:网络
I have a single pc with multiple keyboards, all the capslock lights turn on/off synchronously. (so if one user/keyboard turns on the capslock, everybody types in caps)

I have a single pc with multiple keyboards, all the capslock lights turn on/off synchronously. (so if one user/keyboard turns on the capslock, everybody types in caps)

I was thinking about saving each keyboard's ca开发者_JS百科pslock status in flags but I just realized that the lights won't correspond for each user/keyboard's capslock status.

I just want to know if the capslock light can be turned on/off independently. I'm already planning on disabling the capslock (since I don't really like that key), but in case the client wants to use it I can either find a way to do it or tell them it's impossible.


try

http://www.codeguru.com/Cpp/W-P/system/keyboard/article.php/c2825

a bit involved, but doable :)


you can Programmatically Get and Set the State of the CapsLock Keys using Keybd_Event function
try this:

var
    KeyState: TKeyboardState;
 begin
    GetKeyboardState(KeyState) ;
   if (KeyState[VK_CAPITAL] = 0) then
    begin  //simulate key down
      Keybd_Event(VK_CAPITAL, 1, KEYEVENTF_EXTENDEDKEY or 0, 0) ;
      Keybd_Event(VK_CAPITAL, 1, KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP, 0) ;
    end
    else
    begin  //simulate key up
      Keybd_Event(VK_CAPITAL, 0, KEYEVENTF_EXTENDEDKEY or 0, 0) ;
      Keybd_Event(VK_CAPITAL, 0, KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP, 0) ;
    end;

if you REALLY want to disable a key(which i dont recommend) you can use this library called BlockKeys(i found BlockKeys library at http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21504230.html ):

library BlockKeys;

uses
  Windows,
  Messages;

{$R *.RES}

var
hKeyHook: THandle = 0;
Hooked: Boolean = False;

function HookFunc(Code, VirtualKey, KeyStroke: Integer): Integer; stdcall;
begin
if  VirtualKey in [VK_TAB, VK_CONTROL, VK_MENU, VK_ESCAPE, VK_F1] then
  Result := 32
  else
  Result := CallNextHookEx(hKeyHook, Code, VirtualKey, KeyStroke);
end;


function StartHook: Boolean; export;
begin
Result := False;
if Hooked then
  begin
  Result := True;
  Exit;
  end;

hKeyHook := SetWindowsHookEx(WH_KEYBOARD, HookFunc, hInstance, 0);
if hKeyHook <> 0 then
  begin
  Result := True;
  Hooked := True;
  end;
end;


function StopHook: Boolean; export;
begin
if Hooked then
  Result := UnhookWindowsHookEx(hKeyHook)
  else
  Result := True;
if Result then Hooked := False;
end;

exports
  StartHook,
  StopHook;

begin

end.

hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消