Jump to content
Sign in to follow this  
krolikbest

onkeyup-down

Recommended Posts

Hi,

 

maybe i'm too much used to lazarus or delphi and now have problem:

have choosen visual component, add label1 and directly onkeydown of form1 wrote label1.caption:='Hello', expecting that after pressing whatever on keyboard i'll see on text Hello. instead of that, nothing happens.

{EDIT}

if I first press a <tab> button and then some key then it works. When i press and hold pressed <tab> works as well. Seems that something else is first focused? Could someone explain me that?

Share this post


Link to post
Share on other sites

finally found solution:

<code>

 

 

procedure TForm1.KeyDownEvent(mCode: integer);

begin

case mCode of

66 : labb.caption:='Hello';

end;

end;

 

 

procedure TForm1.InitializeForm;

begin

inherited;

// this is a good place to initialize components

 

asm

window.onkeydown = function(e)

{

TForm1.KeyDownEvent(Self,e.keyCode);

}

window.focus();

end;

KeyDownEvent(0);

end;

 

</code>

 

But not sure if there is some more elegant solution?

Share this post


Link to post
Share on other sites

FYI: sometimes you need to "edit -> submit" again in order to fix the formatting of the post.

 

To clarify; you have used the OnKeyDown (TKeyDownEvent) but it doesn't work as intended for you?

 

If you are trying to use the Form's OnKeyDown even you may have to call .SetFocus; in InitializeForm.

Share this post


Link to post
Share on other sites

> Yes, i've used OnKeyDown on mainform. but calling setfocus in InitializeForm gives no result.

 

Are you using new alpha? If so, perhaps you need to flag that you intend to listen for keys, I know it's mandatory for custom controls to add cfKeyCapture to CreationFlags, but I'm not sure about added forms and controls on it, check.

 

Alternative is of course to just use MYForm.Handle.addEventListener and make a classic JS event.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×