Link to home
Start Free TrialLog in
Avatar of edhasted
edhastedFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Delphi - get status of Num Lock / Caps Lock / Scroll Lock lights (on or off)

This has been asked historically but I was wondering if there has been any progress on this issue in the intervening years.

What I need is a was of accurately displaying whether the Num/Caps/Scoll lock lights are on or off.

The reasons behind this is simple. I am writing a key stroke logger to be used with blind users. Rather than second guess what keystrokes they have pressed the logger displays what buttons they have actually pressed. However it is vital for their remote tutors to know whether the Num and Caps locks are on or off.

Can this be done reliably?

With thanks,

Ed
ASKER CERTIFIED SOLUTION
Avatar of Mike Littlewood
Mike Littlewood
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try this

var
  k: TKeyboardState;
begin
  GetKeyboardState(k);
  Edit1.Text := IntToStr(k[VK_NUMLOCK]);
  Edit2.Text := IntToStr(k[VK_CAPITAL]);
  Edit3.Text := IntToStr(k[VK_SCROLL]);
Avatar of edhasted

ASKER

Does LowOrderBitSet work in Delphi 5? If not is there a workaround - I'm getting an "Undeclared Idenfier" from the compiler.

Thanks,

Ed
Apologies - I copied over the code and left out the LowOrderBit function.

Ed
Firstly many thanks to Mike Littlewood for his answer. I have set it up so three panels alter their colour from black to green depending on whether the lights are on or off. So far it works perfectly.

What I find strange reading the previous stabs at this problem was that the contributors felt that it could not be done.

This appears to crack the problem.

With many thanks,

Ed
Glad I could help.