Home > Object Pascal, OP4JS, Smart Mobile Studio > Keyboard input for Smart Mobile Studio

Keyboard input for Smart Mobile Studio

February 14, 2015 Leave a comment Go to comments

Smart Mobile Studio provides a rich and well planned out RTL. However, the RTL does take for granted that you do know you way around HTML and that you write more hands-on code than some may be comfortable with.

One question I often get is “Why doesnt the KeyDown and KeyUp events work”. Well, they do! But the law of HTML5 is that no element can accept input (or have focus) without a tabindex being set first. And since many of the standard controls that ship with the RTL dont expect keyboard input (or need keyboard input for that matter), the key-target value was not set by default.

So the solution to why the keyboard event(s) don’t fire on your TW3Panels and other containers (including forms) is quite simply that. Here is how you get keyboard events working in your form:

procedure TForm1.InitializeForm;
begin
  inherited;

  // Set the key-down event
  OnKeyDown:=Procedure (sender:TObject;Key:Integer)
  begin
    writeln(key);
  end;

  // set the key-up event
  OnClick:=procedure (sender:TObject)
  Begin
    if visible then
    self.SetFocus;
  end;

  // this makes the form a key-event target
  w3_setAttrib(self.handle,'tabindex',0);
end;

Note: In the next update of Smart Mobile Studio, all TW3CustomControls initialize the tabindex automatically, so by default all controls will be initialized to accept keyboard input.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: