1. In WordPad, on its status bar, it has a panel that shows CAP then the
Caps lock is on. How can I do this in my Delphi Word Processor.
I've tried this but nothing happeneds:
procedure TfrmMain.FormKeyPress(Sender: TObject; var Key: Char);
begin
If Key = 'Cap Lock' then
StatusBar.Panels.Items[2].text := 'CAP'
else
StatusBar.Panels.Items[2].text := ' ';
end;
What am I doing wrong and how could I do the same for Num lock and Scroll
lock.
2. How could I use Insert and overtype modes in my TRichEditWithOle
component (It is Identical to TRichEdit except it Supports Ole), then how
could I show what it is in another Status bar Panel.
Thanks a lot
Steven
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnIdle := MyIdleHandler;
end;
procedure TForm1.MyIdleHandler(Sender: TObject; var Done: Boolean);
var
Ks: TKeyBoardState;
begin
GetKeyBoardState(Ks);
if (Ks[20] and 1) = 1 then
CapsLockShape.Brush.Color := clLime
else
CapsLockShape.Brush.Color := clBtnFace;
if (Ks[144] and 1) = 1 then
NumLockShape.Brush.Color := clLime
else
NumLockShape.Brush.Color := clBtnFace;
if (Ks[145] and 1) = 1 then
ScrollLockShape.Brush.Color := clLime
else
ScrollLockShape.Brush.Color := clBtnFace;
end;
Finn Tolderlund
Steven Graham <f...@motepark80.freeserve.co.uk> skrev i en
nyhedsmeddelelse:7vhj11$66...@forums.borland.com...
Why so you *expect* this to work? Key is clearly defined as a single Char, so
it cannot possibly be a key name string.
Finn gave you a possible approach: simply check for the state of the keys you
are interested in. His code can be made a lot clearer by using the proper
virtual key codes instead of plain numbers, though, so i repeat it here with
modifications. I have removed the actions since you probably want to display
strings in the statuspanels of a statusbar. You have to add the appropriate
code instead of the comments.
procedure TForm1.MyIdleHandler(Sender: TObject; var Done: Boolean);
var
Ks: TKeyBoardState;
begin
GetKeyBoardState(Ks);
if (Ks[VK_CAPITAL] and 1) = 1 then
{ caps lock engaged }
else
{ caps lock not engaged };
if (Ks[VK_NUMLOCK] and 1) = 1 then
{ NumLock engaged }
else
{ NumLock not engaged };
if (Ks[VK_SCROLLOCK] and 1) = 1 then
{ ScrollLock engaged }
else
{ ScrollLock not engaged };
end;
> 2. How could I use Insert and overtype modes in my TRichEditWithOle
> component (It is Identical to TRichEdit except it Supports Ole), then how
> could I show what it is in another Status bar Panel.
The rich edit control always starts out in insert mode and changes state on
every press of the VK_INSERT (Ins) key while it has focus. It really counts key
events instead of checking the toggle state of the key (that is what the Idle
handler above does). So you have to attach a handler to the richedits OnKeyDown
event to trap the VK_INSERT key as well, to keep track of the rich edits state.
Add a field named InsertMode: Boolean to your form, initialize it to True in
the OnCreate event. The richedit1KeyDown event does this:
If Key = VK_INSERT Then Begin
InsertMode := not InsertMode;
If Insertmode Then
statusbar.Panels.Items[ ... ] := 'INS'
Else
statusbar.Panels.Items[ ... ] := ' ';
End;
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
if (Ks[VK_SCROLLOCK] and 1) = 1 then
frmMain.FStatusBar.Panels.Items[4].text := 'SCR'
else
frmMain.FStatusBar.Panels.Items[4].text := '';
With this part enabled I just get: Undeclaired Identifier VK_SCROLLOCK
Peter Below (TeamB) <10011...@compuXXserve.com> wrote in message
news:VA.00003f62.009a0d8a@noname...
Finn Tolderlund
Steven Graham <f...@motepark80.freeserve.co.uk> skrev i en
nyhedsmeddelelse:7vq899$go...@forums.borland.com...
<Sigh>. That's what i get when relying on memory instead of looking up the
VK code. As Finn stated it is VK_SCROLL.