Jump to content

Grabbing Hardware Key Events in Tizen

Recommended Posts


It is not a common scenario to grab a hardware key event in your application, because you can simply use controls like Editor or Entry when you need to get input from users. However, if you want to make a more advanced application which handles hardware key inputs more detail or especially when you want to do something with the Smart TV remote control key event, you want to grab hardware key events.

How to get hardware key event

Using EcoreEvent class

There is a class defined in ElmSharp called EcoreEvent. You can use this ElmSharp.EcoreEvent<EcoreEventType> class to create the following ecore event types that are being notified.

  • KeyDown
  • KeyUp
  • MouseButtonDown
  • MouseButtonUp
  • MouseButtonCancel
  • MouseMove
  • MouseWheel
  • MouseIn
  • MouseOut

Implementing in application


Here is the preparation in the main page of an application to show which key event is occured. One label named keyDownLabel will show which key down event is occured, the other label named keyDownLabel will show which key up event is occured.

<c:CirclePage xmlns="http://xamarin.com/schemas/2014/forms"
    <StackLayout VerticalOptions="CenterAndExpand">
      <Label x:Name="keyDownLabel"
          Text="Which key is down?"
          HorizontalOptions="CenterAndExpand" />

      <Label x:Name="keyDownLabel"
          Text="Which key is up?"
          HorizontalOptions="CenterAndExpand" />


Now on the cs file, declare and create EcoreEvent with the proper EcoreKeyEventType like below. Here I created EcoreEventType.KeyDown and EcoreEventType.KeyUp to grab the hardware key down and up events. After creations, I added event handlers using On event handler. Both event handler will update the hardware key name and the key code on each labels.

EcoreKeyEventArgs is an EventArgs to record the Ecore event's key name and key code. You can see the defined and supported hardware key name here.

using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Tizen.Wearable.CircularUI.Forms;
using ElmSharp;   // declare using statement

namespace HandleHWKey
    public partial class MainPage : CirclePage
        EcoreEvent<EcoreKeyEventArgs> _ecoreKeyDown;
        EcoreEvent<EcoreKeyEventArgs> _ecoreKeyUp;

        public MainPage()

            _ecoreKeyDown = new EcoreEvent<EcoreKeyEventArgs>(EcoreEventType.KeyDown, EcoreKeyEventArgs.Create);
            _ecoreKeyDown.On += _ecoreKeyDown_On;

            _ecoreKeyUp = new EcoreEvent<EcoreKeyEventArgs>(EcoreEventType.KeyUp, EcoreKeyEventArgs.Create);
            _ecoreKeyUp.On += _ecoreKeyUp_On;

        private void _ecoreKeyDown_On(object sender, EcoreKeyEventArgs e)
            keyDownLabel.Text =  $"{e.KeyName} ({e.KeyCode})";

        private void _ecoreKeyUp_On(object sender, EcoreKeyEventArgs e)
            keyUpLabel.Text = $"{e.KeyName} ({e.KeyCode})";

Running application on emulator

You can see the pressed hardware key name and a key code on the upper label, and the released hardware key name and a key code on the lower label.


For TV developers

If you are developing for Samsung Smart TV and are finding how to simply handle hardware key events, Tizen.TV.UIControls is right there for you. Tizen.TV.UIControls not only provides a variety sets of UI controls for easily creating TV applications, but also have Xamarin.Forms extension features that helps you create TV applications easily. InputEvents feature in this library is the wrapper for this ElmSharp EcoreEvents so you can easily grab keys, for example remote control keys, in your application. Check out the guides and the API reference for InputEvents.

View the full blog at its source

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Topics

    • By Samsung Newsroom
      The S Pen is a stylus exclusive to Samsung’s Note series devices, powered by Bluetooth technology. The S Pen for Note10 devices has accelerometer and 3D gyroscope modules, which enable the stylus to detect air actions, such as single and double button presses, and directional gestures, such as up, down, left, right, clockwise circle, and counter-clockwise circle gestures. You can use the S Pen Remote SDK to map S Pen actions and gestures to features in your application.
      To help you avoid making the same mistakes as I did when I was developing my application with the S Pen Remote SDK, this article describes some common implementation mistakes and their solutions.
      Note: The S Pen for Note9 devices do not support the S Pen Remote SDK, but you can implement single and double button press actions for it in the application configuration file.
      Mistake #1: Too many remote action activities
      The S Pen Remote SDK allows one remote action activity for each application. If you define multiple remote action activities, only one activity is functional.

      Figure 1: Remote action activity in the AndroidManifest.xml file
      Mistake #2: Air actions are disabled
      When you install an application on a device, such as to test it, you must manually enable air actions for the application before the application can respond to S Pen gestures.
      To enable air actions for your application, on the device, go to Settings > Advanced features > S Pen > Air actions, select the application from the App actions list, and toggle the Off switch to On.
      Figure 2: Enable the application in the Air actions settings
      If you want the application to have air actions enabled by default, you need special permission from Samsung to add the enable_key attribute to the remote-actions element in the remote_action.xml file. To obtain permission, submit the following information about your application to [email protected]:
      Application name Package name Information about how air actions are used in your application: Does the application use the media session? Does the application support background playback? Describe the user scenarios in which air actions are used. Mistake #3: Remote_action.xml configuration problems
      If your application is installed on the device but does not appear in the Air actions settings, check that the remote_action.xml file content is defined correctly.
      Common problems include:
      Duplicate action priorities: The priority attribute is a mandatory part of the action element. A smaller number denotes a higher priority. Make sure each action has a unique priority number.
      Figure 3: Priority attributes in action elements
      Incorrectly defined action labels: In the remote_action.xml file, make sure that the label attributes of the action elements refer to resource IDs. You cannot directly implement a text string in the label attribute. You must first define the string as a resource in the strings.xml file within the values directory, then refer to the string’s resource ID in the label attribute of the action element.
      Figure 4: Assign resource IDs to label strings

      Figure 5: Refer to resource IDs in the label attribute
      Hope this blog helps you to integrate the S Pen Remote SDK smoothly by avoiding these mistakes. You can also study the sample application for guidance.
      View the full blog at its source

  • Create New...