How can we handle key pressed on keyboard by user in any script?
#1
Question 
How can we handle key pressed on keyboard by user in any script?

Being inside the gui of spotimc addon when I press ESC and Backspace key I don't come to home/previous screen.
That works only when I am inside some folder and I am looking at tracks of any album( there pressing ESC displays All albums screen inside the spotimc), pressing again ESC/Backspace does nothing.
Where is it blocked?

In keyboard.xml, I have:
PHP Code:
<backspace>Back</backspace>
<
escape>PreviousMenu</escape

How can we handle key pressed on keyboard by user in any script?
For ex: if ESC is pressed, go to Home window.
Reply
#2
This needs to be handled by the script.

In short: The modal running window object receives callbacks to the onAction()-method with the actionID as first positional argument. So the actions "Back" and "PreviousMenu" needs to be handled there to react with the desired action.
My GitHub. My Add-ons:
Image
Reply
#3
Thanks sphere, that worked Smile
Reply
#4
When I press F3 nd F4 I always get the same id 122 why? I need different .
Please help.
Reply
#5
There is no direct mapping from key to action, there is one extra round to abstract the input device. This is to automatically support all kinds of input device like keyboard, (infrared) remote, gamepad, smartphone apps via jsonrpc etc.
You can only map the actions behind the input events like select, menu, ok, fast-forward and so on.
You can have a look to my WhatTheMovie Add-on code for some wide supported actions.

Quoted here:
PHP Code:
#
    
AID_EXIT_BACK = [91013]
    
AID_NUMBERS = [5960616263,
                   
6465666758]
    
ACTION_IDS = ({'AID_PAGE_UP'5},
                  {
'AID_PAGE_DOWN'6},
                  {
'AID_SHOW_INFO'11},
                  {
'AID_PAUSE'12},
                  {
'AID_STOP'13},
                  {
'AID_NEXT_ITEM'14},
                  {
'AID_PREV_ITEM'15},
                  {
'AID_PLAYER_FORWARD'77},
                  {
'AID_PLAYER_REWIND'78},
                  {
'AID_PLAYER_PLAY'79},
                  {
'AID_CONTEXT_MENU'117},
                  {
'AID_VOLUME_UP'88},
                  {
'AID_VOLUME_DOWN'89},
                  {
'AID_SCROLL_UP'111},
                  {
'AID_SCROLL_DOWN'112},
                  {
'AID_HOME'159},
                  {
'AID_END'160}) 
My GitHub. My Add-ons:
Image
Reply

Logout Mark Read Team Forum Stats Members Help
How can we handle key pressed on keyboard by user in any script?0