如何在程序中显示键盘状态?

potato 2000-05-19 09:18:00
如何在程序中显示键盘状态?
如何在程序中显示Insert,NumLock,CapsLock等按键的状态?就如同在Word中能清楚的知道现在是否是在插入状态一样。
...全文
109 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
kxy 2000-05-19
  • 打赏
  • 举报
回复
Question

How to control caps lock key?

Answer

A:
In Windows enviroment, you can look at the keyboard lights values, but you can't
set it, because Windows intercept your peek in the memory and blocks it (I tryed
under Windows 95, maybe under Windows 3.11 it works). However, you should be able
to look at the status.
Try to put this simple code in a function:
const
SCROLLLOCK = 1;
NUMLOCK = 2;
CAPSLOCK = 4;
var
Status: Byte;
PntK: ^Byte;
begin
PntK := Ptr($40, $97); {directly point in memory}
Status := Byte(PntK^); {read the status}
if (NUMLOCK and Status) = NUMLOCK then {if NUM LOCK is on}
Status := Status and (255 - NUMLOCK) {turn it off}
else
Status := Status or 2; {turn it on}
Pntk^ := Status; {poke in memory (don't works)}
end;

A:

I use this procedures to turn on the caps lock if it isn't already on when
the user enters my DBloockup combo. This gets rid of the nasty problem
of case-sensitive indexes.
procedure TMainForm.StudentLookupEnter(Sender: TObject);
Var Level : Integer;
KeyState : TKeyBoardState;
begin
{check if caps-lock is on - if not turn it on}
Level := GetKeyState(VK_CAPITAL);
GetKeyboardState(KeyState);
CapsLockStatus := KeyState;
If Level = 0 then
begin
KeyState[VK_CAPITAL] := 1;
setKeyboardState(KeyState);
end;
end;



Question

I need my application to be able to "stuff keystrokes" into the keyboard
buffer.
My application needs to be able to do this while minimzed and the
keystrokes should effect the active Window and appear "typed".

Answer
A:
{this proc interrogates the numlock key and sets the state}
{according to the value of bOn}
procedure TIndexForm.ToggleNumLockKey(bOn: Boolean);
var
KeyState : TKeyBoardState;
begin
GetKeyboardState( KeyState );
if bOn then KeyState[VK_NUMLOCK] := 1
else KeyState[VK_NUMLOCK] := 0;
SetKeyboardState( KeyState );
end;

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧