Jump to content


Photo

onkeyup-down


  • Please log in to reply
4 replies to this topic

#1 krolikbest

krolikbest
  • Members
  • 13 posts

Posted 08 October 2017 - 05:07 PM

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?

#2 krolikbest

krolikbest
  • Members
  • 13 posts

Posted 08 October 2017 - 07:09 PM

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?

#3 recursiveElk

recursiveElk
  • Members
  • 60 posts

Posted 08 October 2017 - 10:39 PM

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.

#4 krolikbest

krolikbest
  • Members
  • 13 posts

Posted 09 October 2017 - 09:22 PM

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

#5 Igor Savkic

Igor Savkic
  • Members
  • 188 posts

Posted 09 October 2017 - 10:38 PM

> 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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users