Board index » delphi » Check Keyboard input

Check Keyboard input

Hi ,

I am gettingmy user to inout data in a TStringGrid.

Since I am using D5 VCL i have to do the masking manually.That is i want to
filter out the unwanted keystrokes.

So if the usr types a letter in a number filed the program shouldn;t display
it. In the good old Pascal days we simply cleared thekeyboard buffer when we
foud someunwanted key; how is it done in Delphi??

Thanks for any help.

Best wishes

Chaitanya

 

Re:Check Keyboard input


use the OnKeyPressed or OnKeyDown event.

Alfred.

"Chaitanya" <sa...@vsnl.com> schreef in bericht news:3b781781_2@dnews...

Quote
> Hi ,

> I am gettingmy user to inout data in a TStringGrid.

> Since I am using D5 VCL i have to do the masking manually.That is i want
to
> filter out the unwanted keystrokes.

> So if the usr types a letter in a number filed the program shouldn;t
display
> it. In the good old Pascal days we simply cleared thekeyboard buffer when
we
> foud someunwanted key; how is it done in Delphi??

> Thanks for any help.

> Best wishes

> Chaitanya

Re:Check Keyboard input


Chaitanya,

Use the OnKeyPress event handler.

================
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
{--- #32 is a space, #45 is a hyphen, #0 is a nul --- }
  if Key IN [#45,#32] then   { or if Key IN [' ','-'] then }
  begin
    Key := #0;
  end;
end;
================

Craig Hunt

Quote
"Chaitanya" <sa...@vsnl.com> wrote in message news:3b781781_2@dnews...
> Hi ,

> I am gettingmy user to inout data in a TStringGrid.

> Since I am using D5 VCL i have to do the masking manually.That is i want
to
> filter out the unwanted keystrokes.

> So if the usr types a letter in a number filed the program shouldn;t
display
> it. In the good old Pascal days we simply cleared thekeyboard buffer when
we
> foud someunwanted key; how is it done in Delphi??

> Thanks for any help.

> Best wishes

> Chaitanya

Re:Check Keyboard input


Thanks for the inputs.

I also want to try and "fake" the inputs, ie if the user preses enter i want
th StringGrid to behave as if tab key was pressed.

It doesn;t work if i say:

procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
 if Key = #13 then  key:= #0;
end;

Any more suggestion?

Thanks again

Chaitanya

Quote
Craig Hunt <CraigHu...@hotmail.com> wrote in message

news:3b78370e_1@dnews...
Quote
> Chaitanya,

> Use the OnKeyPress event handler.

> ================
> procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
> begin
> {--- #32 is a space, #45 is a hyphen, #0 is a nul --- }
>   if Key IN [#45,#32] then   { or if Key IN [' ','-'] then }
>   begin
>     Key := #0;
>   end;
> end;
> ================

> Craig Hunt

> "Chaitanya" <sa...@vsnl.com> wrote in message news:3b781781_2@dnews...
> > Hi ,

> > I am gettingmy user to inout data in a TStringGrid.

> > Since I am using D5 VCL i have to do the masking manually.That is i want
> to
> > filter out the unwanted keystrokes.

> > So if the usr types a letter in a number filed the program shouldn;t
> display
> > it. In the good old Pascal days we simply cleared thekeyboard buffer
when
> we
> > foud someunwanted key; how is it done in Delphi??

> > Thanks for any help.

> > Best wishes

> > Chaitanya

Re:Check Keyboard input


begin
    if Key = #13 then Key := #0;
    Form1.FindNextContol(...)
end;

See OLH for parameters.

Alfred.

"Chaitanya" <sa...@vsnl.com> schreef in bericht news:3b7aa276_1@dnews...

Quote
> Thanks for the inputs.

> I also want to try and "fake" the inputs, ie if the user preses enter i
want
> th StringGrid to behave as if tab key was pressed.

> It doesn;t work if i say:

> procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
> begin
>  if Key = #13 then  key:= #0;
> end;

> Any more suggestion?

> Thanks again

> Chaitanya

Re:Check Keyboard input


Hi

this is what i get in th OLH:

function FindNextControl(CurControl: TWinControl; GoForward, CheckTabStop,
CheckParent: Boolean): TWinControl;

I am not sure about the parameters, but in any case how would it send a tab
key to the component (stringgrid in this case)?

Chaitanya
Alfred ten Hoeve <Alfred.NoS...@SimpelProg.nl> wrote in message
news:3b7ae3d0_2@dnews...

Quote
> begin
>     if Key = #13 then Key := #0;
>     Form1.FindNextContol(...)
> end;

> See OLH for parameters.

> Alfred.

> "Chaitanya" <sa...@vsnl.com> schreef in bericht news:3b7aa276_1@dnews...
> > Thanks for the inputs.

> > I also want to try and "fake" the inputs, ie if the user preses enter i
> want
> > th StringGrid to behave as if tab key was pressed.

> > It doesn;t work if i say:

> > procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
> > begin
> >  if Key = #13 then  key:= #0;
> > end;

> > Any more suggestion?

> > Thanks again

> > Chaitanya

Re:Check Keyboard input


Sorry, misunderstood your question.
I was thinking you would the cursor go to the next control on the form.
A normal Stringgrid doesn't respond to TAB-key's. So what are you trieing to
do?

If you want to go to the next column, you can use this one:

procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
    if Key = VK_RETURN
    then if StringGrid1.EditorMode
            then begin
                      SendMessage(StringGrid1.Handle,WM_KEYDOWN, VK_RIGHT,
0);
              Key := VK_RIGHT;
            end
       else begin
              Key := VK_RIGHT;
            end;
end;

Sorry for the layout, but I think you get it.

Alfred.

"Chaitanya" <sa...@vsnl.com> schreef in bericht news:3b7c1330_1@dnews...

Quote
> Hi

> this is what i get in th OLH:

> function FindNextControl(CurControl: TWinControl; GoForward, CheckTabStop,
> CheckParent: Boolean): TWinControl;

> I am not sure about the parameters, but in any case how would it send a
tab
> key to the component (stringgrid in this case)?

> Chaitanya

Other Threads