Introduction
A TV is mostly a display device that provides an experience to the user rather than the user interacting with it all the time. The common way for the user to interact with the TV is the TV remote. The previous post mentioned about various controlling the remote key events in Tizen TV. Tizen TV have multiple ways to interact with the user like Mouse, Keyboard, GamePad, etc. This article covers the concepts related to handling mouse events in Tizen TV applications.
Why handle mouse events?
Mostly for a TV experience, the TV remote control is probably the only interaction device that the user needs. But in the case of modern TVs, the users are using it more than kind of a TV device. Also since the TVs provide connection support to many external devices including the mouse, providing support for the mouse device has become necessary when we develop any applications for the Tizen TV platform.
Connecting mouse to the TV
Connecting a mouse or a pointing device to the TVs is pretty much straight forward. We have to connect the device directly to the TV port based on the mouse (wired or wireless). Once the mouse is connected to the TV, we can see an arrow on the screen just like a regular PC. We can use the arrow for selecting options on the screen, opening context/hidden menu, TV based browsing, entering input using the IME editor easily, scrolling functionality, and various TV-based games that have mouse support.
Handling mouse events via code
When developing an application, the developer has to decide whether the application needs support for mouse devices. He has to toggle the following setting in the config.xml file to enable mouse / pointer device support.
<tizen:setting pointing-device-support='enable' />
By default, the above setting will be disabled. If disabled, your application will not show the mouse pointer. This avoids unwanted confusion. Also if the mouse pointer is shown in your application and if it is not handled via code, this will cause your application to be rejected during the review process. Once the above code setting is enabled, you are ready to handle mouse pointer events in your application. Mouse events are based on the w3c mouse point events standard.
Code sample
First we start of with adding click event listeners to the desired elements to needs to handle the mouse click event. The following is the code sample for that
<div id='button' ... onclick='handleKeyClick();'> ... </div>
Then we will define the logic inside the handler function that is triggered when the specified element is clicked
function handleKeyClick () {
// Something you want to do
...
}
The above sample code handles specific click event from mouse. Similar way you can extend your code to provide support for other types of mouse events.
Conclusion
So we have seen the basic idea of enabling mouse events support in Tizen TV applications, and also we went through the sample code and saw how to handle a basic mouse click event. Enabling or disabling mouse support is based on the needs of your application. If you think, your application does not need any mouse support, you can simply ignore it by disabling the setting in config.xml. In the next article, we will look into handling input events from other peripheral devices like the keyboard.