Forum > General

OnKeyPress (on active form) ?

(1/2) > >>

seba22:
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: ---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;     
--- End code ---

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:
Set form property KeyPreview to True.

seba22:
Thank You ;)


For people who want to this same, this is ready code:

--- Code: ---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; 
--- End code ---

Imants:
If you put controls on your form like editbox is your procedure working?

Martin_fr:

--- Quote from: Imants on December 20, 2010, 03:40:14 pm ---If you put controls on your form like editbox is your procedure working?

--- End quote ---

- 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

Navigation

[0] Message Index

[#] Next page

Go to full version