Recent

Author Topic: OnKeyPress (on active form) ?  (Read 8560 times)

seba22

  • Full Member
  • ***
  • Posts: 136
OnKeyPress (on active form) ?
« on: December 19, 2010, 09:40:22 pm »
Welcome,

I have question, i need create stay on top form.

I found when i use border - none, then stay on top style is working.

But i cant move my form.
I get idea to create  form what can be moved by arrow keys.

I would like do to it using on key press, check if arrow was pressed  get form left :=   form.left + 10  or form.top + 10 etc.

but the problem is, i cant get function onkeypress working.

Code: [Select]
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
  );
begin
   //if Key = vk_left then form1.left:=form1.left-10;
  showmessage('test);
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
begin
   showmessage('test');
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  showmessage('test');
end;     

i try this all three triggers.
on windows and linux (gtk2).

No showmessage show, i was hitting every key on my keyboard.

Any idea what can make this working ?

Regards

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: OnKeyPress (on active form) ?
« Reply #1 on: December 19, 2010, 09:56:11 pm »
Set form property KeyPreview to True.

seba22

  • Full Member
  • ***
  • Posts: 136
Re: OnKeyPress (on active form) ?
« Reply #2 on: December 19, 2010, 10:08:38 pm »
Thank You ;)


For people who want to this same, this is ready code:
Code: [Select]
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
  );
begin
   Case Key of
    VK_UP : form1.Top:=form1.top-10;
    VK_DOWN : form1.top:=form1.top+10;

        VK_LEFT : form1.left:=form1.left-10;
        VK_RIGHT : form1.left:=form1.left+10;

    end;
end; 


Imants

  • Full Member
  • ***
  • Posts: 198
Re: OnKeyPress (on active form) ?
« Reply #3 on: December 20, 2010, 03:40:14 pm »
If you put controls on your form like editbox is your procedure working?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12345
  • Debugger - SynEdit - and more
    • wiki
Re: OnKeyPress (on active form) ?
« Reply #4 on: December 20, 2010, 03:54:48 pm »
If you put controls on your form like editbox is your procedure working?

- It should (with FormKeyPrevie
- It does on Win (last time I checked)
- There is a bug on GTK2: http://bugs.freepascal.org/view.php?id=17775

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: OnKeyPress (on active form) ?
« Reply #5 on: December 20, 2010, 10:13:11 pm »
I am not sure of your workaround (but of course - I don't work with GTK2). Following solution works in Qt4.
I have one main form and several tool windows over it.
Properties of tool windows are default except these:
BorderStyle:=bsToolWindow;
FormStyle:=fsStayOnTop or fsNormal - this is not so important because:
I create these tool windows invisible (Visible:=False;) and later after creation of main form I call ToolWindow.ShowOnTop; - everything works as expexted but not tested yet on other platforms.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018