Results 1 to 3 of 3

Thread: Boxee keyboard events

  1. #1
    Join Date
    Feb 2012
    Posts
    9

    Default Boxee keyboard events

    Hi,

    I have reviewed lots of discussions about using the keyboard mode of boxee on a html5 application, but can someone please post a simple but complete example on how to detect something as simple as boxee.onKeyboardKeyRight ?

    Currently, my home html file enters boxee keyboard mode through:

    Code:
    boxeeAPI.keyboardMode();
    The controller javascript is being imported obviously:

    Code:
    <script type='text/javascript' src='lib/js/boxee-api.js'></script>
    Now, the problem is, that on the above javascript I have the following function that simply does not work:

    Code:
      boxee.onKeyboardKeyUp = function () {
              boxee.exec("showNotification('Key pressed')");
      };
    Also tried:

    Code:
      boxee.onKeyboardKeyUp = function () {
              alert("Test");
      };
    Can anyone please help?

    Thanks in advance.

  2. #2
    Join Date
    Jan 2011
    Location
    Denmark
    Posts
    31

    Default

    I think your problem is that you call boxee.onKeyboardKeyUp... in DOM context instead of control script context. Try to read http://developer.boxee.tv/Control_Script_Context.

    I map the the navigation keys to arrow keys to allow testing in a regular webbrowser

    Here is a complete working example

    Code:
    <!DOCTYPE html>
    <html>
    	<head>
    		<title>Boxee Test</title>
    		<meta charset="UTF-8" />
    	</head>
    <body>
    
        <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
        <script type="text/javascript" src="boxee-api.js"></script>
    	<script type="text/javascript">
    	$(function () {
    		boxeeAPI.keyboardMode();
    	
    		function setupPlayer() {
    			boxee.onKeyboardKeyLeft  = function() {browser.keyPress(browser.KEY_LEFT)};
    			boxee.onKeyboardKeyRight = function() {browser.keyPress(browser.KEY_RIGHT)};
    			boxee.onKeyboardKeyUp    = function() {browser.keyPress(browser.KEY_UP)};
    			boxee.onKeyboardKeyDown  = function() {browser.keyPress(browser.KEY_DOWN)};
    			boxee.onKeyboardKeyEnter = function() {browser.keyPress(browser.KEY_RETURN)};
    			boxee.onKeyboardKeyBack  = function() {browser.keyPress(browser.KEY_ESCAPE)};
    		}
    	
    		// Register in Control Context (see http://developer.boxee.tv/Control_Script_Context)
    		boxee.exec(setupPlayer);
    		// Execute in Control Context (see http://developer.boxee.tv/Control_Script_Context)
    		boxee.exec("setupPlayer()");
    		
    		// Browser control
    		$(document).keydown(function(e) {
    			var code = (e.keyCode ? e.keyCode : e.which);
    	
    			switch(code) {
    			case 13:
    				boxeeAPI.notify("Enter",1);
    				break;
    			case 27:
    				boxeeAPI.notify("Back",1);
    				break;
    			case 37:
    				boxeeAPI.notify("Left",1);
    				break;
    			case 38:
    				boxeeAPI.notify("Up",1);
    				break;
    			case 39:
    				boxeeAPI.notify("Right",1);
    				break;
    			case 40:
    				boxeeAPI.notify("Down",1);
    				break;
    			}
    		});
    	});
    	</script>
    </body></html>

  3. #3
    Join Date
    Feb 2012
    Posts
    9

    Thumbs up

    Hi hitolaus,

    You are absolutely right. We have been stuck with this for two days.

    Thanks a lot for your help.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •