Kodi Community Forum

Full Version: Help with keymapping n5902
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
ok, so ive purchased a lenovo n5902 wireless keyboard/mouse and need some help mapping some keys.
n5902

Ill start with the simple problem. I'd like to map the info command to my control key. In keyboard.xml ive tried ctrl, ctr, ctl, and control. None of them seem to work. Is control not allowed to be mapped by itself? or am i using an improper term for it? I would also like to map my shutdown menu to the windows key. Ive tried "win" as that was used later on down in the keyboard.xml. But again, it does not seem to work. Im assuming im just not using the correct term to define the key i want pressed.

There are 3 more buttons on this remote id like to map as well. in the top right hand corner you have an "internet" button, and a "next Page". in the bottom right corner there is a "menu" button. The problem is that i dont know what keys they actually use. Im assuming its some kind of combination but i cant figure it out. Lenovo's documentation fails to provide any information here, and ive searched through many forums but still cant find my answer. So im just wondering if anybody here has this remote and could point me in the right direction. Ive also tried keylogger programs to see if they could tell me what keys were pressed, but they just dont display anything for they keys i want.
This works:

Code:
<keymap>
  <global>
    <keyboard>
      <leftctrl mod="ctrl">Notification(KeyPress, leftctrl, 2)</leftctrl>
      <rightctrl mod="ctrl">Notification(KeyPress, rightctrl, 2)</rightctrl>
    </keyboard>
  </global>
</keymap>

You need the mod="ctrl" because, erm, the control key is down :-)
thank you, that worked great. got any ideas for the windows key?
If you're trying to work out what key mappings to use the trick is to enable debug logging from System settings, System, Debugging, then press the key a few times and look at the debug log (see http://wiki.xbmc.org/index.php?title=Log_File). In the case of the control key, when I press left control my log shows:

Code:
DEBUG: SDLKeyboard: scancode: 1d, sym: 0132, unicode: 0000, modifier: 40
DEBUG: CApplication::OnKey: ctrl-leftctrl (1f0d0) pressed, action is

which is how I knew the mapping was <leftcontrol mod="ctrl">. If I press the left windows key I get:

Code:
DEBUG: SDLKeyboard: scancode: 5b, sym: 0137, unicode: 0000, modifier: 10
DEBUG: CApplication::OnKey: win-leftwindows (10f0d6) pressed, action is

so the mapping would be <leftwindows mod="win">. However on Windows you can't stop this opening the Start menu so it isn't much use. It should work on Linux or OSX though.
thank you for the info. I now have the windows key successfully mapped. Explorer never starts on this machine, so the start menu is a non-issue. However, it could be avoided by runinng an autohotkey, or autoit script.

Using debug logging and checking it out, ive been able to map the "menu" key. I'm having trouble understanding what exactly is going on when i press the internet key. here is a cut-out from the log. i tried 0, but nothing. actually it made the keyboard completely stop responding in xbmc

Code:
20:11:33 T:1708   DEBUG: WinEventsWin32.cpp: APPCOMMAND 7
20:11:33 T:1708   DEBUG: CApplication::OnAppCommand: appcommand 7, trying action FirstPage
20:11:33 T:1708   DEBUG: SDLKeyboard: scancode: 00, sym: 0000, unicode: 0000, modifier: 0
20:11:33 T:1708   DEBUG: CApplication::OnKey: 0 (f200) pressed, action is

Ideally, i would like to be able to press it and have it open firefox. As i've stated before, explorer dos not start on this machine. So i would need to be able to press this key and have it open firefox through advanced launcher (wich i already have configured in xbmc). I may have to do an autoit script to get this working but i would like to avoid that if at all possible. perhaps their is a way to assign a key to a specific favorite. im also curious if there is a way to map a key to go to the home screen?
Update:

I've found this wonderful resource here. I read everything carefully, and followed the instructions very close but still having issues. I downloaded the "showkey" program they recommended, and i must admit it is fantastic. I surely will use it in the future, but... Its not working for my internet key. I downloaded, tested it with basic keys, and then used my interent key. It indeed did give me code to use in keyboard.xml, but it did not wrok.

it gave me this
Code:
<browser_home>Notification(Key, browser_home, 3)</browser_home>
i also tried the following as stated here
Code:
<key id="172">Notification</key>

I put that in my keyboard.xml almost certain that it would work. But no. I tried just browser instead of browser_home, still nothing. If it helps, when i press the button on the home screen, it always selects pictures.
one more question. what does the stuff in parenthesis do? ex. (key,browser_home, 3) In my previous settings i had to remove that in order to get it working. i attempted to do so for this as well

oh, and the log has remained unchanged throughout. Says the same thing every time
In Windows pressing a multimedia key generates a Windows message called WM_APPCOMMAND, then it also generates a keypress message, so XBMC receives two signals. To avoid duplication XBMC processes the appcommand but ignores the keypress, so you need to change the action XBMC takes on the appcommand.

To change the appcommand create a file called appcommand.xml in the same directory as the keyboard.xml. The file needs to contain something like:

Code:
<keymap>
  <global>
    <appcommand>
      <browser_home>Notification(Key, browser_home, 3)</browser_home>
    </appcommand>
  </global>
</keymap>

You can replace the Notification function by whatever you want to launch Firefox. I tend to write a short Python script to do this, but I guess AdvancedLauncher would work as well. If you want to use a script use the mapping:

Code:
<browser_home>RunScript(C:\whatever\LaunchFirefox.py)</browser_home>

and put something like this in the script:

Code:
import subprocess

print "Starting script RunIE.py"

# Open IE and wait for it to exit
child = subprocess.Popen("\"C:\Program Files (x86)\Internet Explorer\iexplore.exe\"")
rc = child.wait()

# Run XBMC again: this will simply set the focus back to the current instance
child = subprocess.Popen("C:\Program Files (x86)\XBMC\XBMC.exe")

Now i can control the key by editing the appcommand.xml, but i cant get it to do exactly what i want. How firefox is currently set up isnt the greatest. I use advanced launcher to open up an autoit script (used to close the program by pressing escape). This points to a batch file that closes all other instances of firefox before opening a new one. And finally the advanced launcher entry is favorited and added to the main screen. I would like to remove firefox from the main screen and use only the internet button to access.

I tried using your python script to point to the autoit script i made, but didnt work. The script ran and disappeared before i could read it but no firefox came up. What's my best option here?
You'll have to modify my script because as it stands it will launch Internet Explorer, and even then it won't work on 32 bit Windows because the "Program Files (x86)" directory only exists in 64 bit Windows. In tbe subprocess.Popen line replace the IE executable with the full filename of Firefox.

If the script gives an error you'll be able to see what the error was in the debug log: http://wiki.xbmc.org/index.php?title=Log_File
I think you misunderstood my issue. Your file works fine for opening ie. I said that i tried changing the file path in ur script to point to my autoit launcher (in the form of a .exe). It did not do anything, and for some reason it does not do anything when i point to firefox.exe. In xbmc's log, nothing is displayed. It only show they keypress and nothing after it.

edit: typo in my appcommand.xml here's what the log shows

Code:
12:21:50 T:1732   DEBUG: WinEventsWin32.cpp: APPCOMMAND 7
12:21:50 T:1732   DEBUG: CApplication::OnAppCommand: appcommand 7, trying action RunScript (C:\Program Files (x86)\Mozilla Firefox\launcher2.py)
12:21:50 T:1732    INFO: initializing python engine.
12:21:50 T:1732   DEBUG: new python thread created. id=9
12:21:50 T:1732   DEBUG: SDLKeyboard: scancode: 00, sym: 0000, unicode: 0000, modifier: 0
12:21:50 T:1732   DEBUG: CApplication::OnKey: 0 (f200) pressed, action is
12:21:50 T:1312   DEBUG: Thread XBPyThread start, auto delete: 0
12:21:50 T:1312   DEBUG: Python thread: start processing
12:21:50 T:1312  NOTICE: -->Python Interpreter Initialized<--
12:21:50 T:1312   DEBUG: XBPyThread::Process - The source file to load is C:\Program Files (x86)\Mozilla Firefox\launcher2.py
12:21:50 T:1312   DEBUG: XBPyThread::Process - Setting the Python path to C:\Program Files (x86)\Mozilla Firefox;C:\Users\Media\AppData\Roaming\XBMC\addons\script.module.cryptopy\lib;C:\Users\Media\AppData\Roaming\XBMC\addons\script.module.demjson\lib;C:\Program Files (x86)\XBMC\addons\script.module.simplejson\lib;C:\Users\Media\AppData\Roaming\XBMC\addons\script.module.beautifulsoup\lib;C:\Program Files (x86)\XBMC\addons\script.module.pil\lib;C:\Users\Media\AppData\Roaming\XBMC\addons\script.common.plugin.cache\lib;C:\Users\Media\AppData\Roaming\XBMC\addons\script.module.simple.downloader\lib;C:\Users\Media\AppData\Roaming\XBMC\addons\script.module.parsedom\lib;C:\Users\Media\AppData\Roaming\XBMC\addons\script.web.viewer\lib;C:\Users\Media\AppData\Roaming\XBMC\addons\script.module.elementtree\lib;C:\Program Files (x86)\XBMC\addons\script.module.pysqlite\lib;C:\Program Files (x86)\XBMC\system\python\DLLs;C:\Program Files (x86)\XBMC\system\python\Lib;C:\Program Files (x86)\XBMC\python26.zip;C:\Program Files (x86)\XBMC\system\python\lib\plat-win;C:\Program Files (x86)\XBMC\system\python\lib\lib-tk;C:\Program Files (x86)\XBMC;C:\Program Files (x86)\XBMC\system\python;C:\Program Files (x86)\XBMC\system\python\lib\site-packages;
12:21:50 T:1312   DEBUG: XBPyThread::Process - Entering source directory C:\Program Files (x86)\Mozilla Firefox
12:21:50 T:1312  NOTICE: Starting script RunIE.py
12:21:50 T:1312    INFO: Scriptresult: Success
12:21:50 T:1312    INFO: Python script stopped
12:21:50 T:1312   DEBUG: Thread XBPyThread 1312 terminating
12:21:50 T:1732   DEBUG: waiting for python thread 9 to stop
12:21:50 T:1732   DEBUG: python thread 9 destructed

I don't see any obvious error
Ah, I see. The problem must be the subprocess.Popen call. The funny thing is that if there's an error, e.g. if you mis-spell the executable file name, you get a "script failed" pop-up and an error in the log. The only explanation I can think of is that the script is starting the executable you specified but the app is immediately exiting again.

You could try opening a command prompt, typing:

Code:
cd "C:\Program Files (x86)\Mozilla Firefox"

then typing the executable file name as it is in the script (converting any \" to "). You could try changing the script to something like:

Code:
import subprocess

print "Starting script RunIE.py"

# Open IE and wait for it to exit
processname = "C:\Program Files (x86)\Internet Explorer\iexplore.exe"
print "subprocess.Popen(" + processname + ")"
child = subprocess.Popen(processname)
rc = child.wait()

# Run XBMC again: this will simply set the focus back to the current instance
child = subprocess.Popen("C:\Program Files (x86)\XBMC\XBMC.exe")

Just to make sure you're running what you think you are.
Still not quite working. First, im not sure why you had me open firefox through command line. It opened up..
Using your script, i am now getting a script failed error. Here's the log

Code:
13:39:56 T:2340   DEBUG: WinEventsWin32.cpp: APPCOMMAND 7
13:39:56 T:2340   DEBUG: CApplication::OnAppCommand: appcommand 7, trying action RunScript (C:\Program Files (x86)\Mozilla Firefox\launcher2.py)
13:39:56 T:2340    INFO: initializing python engine.
13:39:56 T:2340   DEBUG: new python thread created. id=10
13:39:56 T:2340   DEBUG: SDLKeyboard: scancode: 00, sym: 0000, unicode: 0000, modifier: 0
13:39:56 T:2340   DEBUG: CApplication::OnKey: 0 (f200) pressed, action is
13:39:56 T:2712   DEBUG: Thread XBPyThread start, auto delete: 0
13:39:56 T:2712   DEBUG: Python thread: start processing
13:39:56 T:2712  NOTICE: -->Python Interpreter Initialized<--
13:39:56 T:2712   DEBUG: XBPyThread::Process - The source file to load is C:\Program Files (x86)\Mozilla Firefox\launcher2.py
13:39:56 T:2712   DEBUG: XBPyThread::Process - Setting the Python path to C:\Program Files (x86)\Mozilla Firefox;C:\Users\Media\AppData\Roaming\XBMC\addons\script.module.cryptopy\lib;C:\Users\Media\AppData\Roaming\XBMC\addons\script.module.demjson\lib;C:\Program Files (x86)\XBMC\addons\script.module.simplejson\lib;C:\Users\Media\AppData\Roaming\XBMC\addons\script.module.beautifulsoup\lib;C:\Program Files (x86)\XBMC\addons\script.module.pil\lib;C:\Users\Media\AppData\Roaming\XBMC\addons\script.common.plugin.cache\lib;C:\Users\Media\AppData\Roaming\XBMC\addons\script.module.simple.downloader\lib;C:\Users\Media\AppData\Roaming\XBMC\addons\script.module.parsedom\lib;C:\Users\Media\AppData\Roaming\XBMC\addons\script.web.viewer\lib;C:\Users\Media\AppData\Roaming\XBMC\addons\script.module.elementtree\lib;C:\Program Files (x86)\XBMC\addons\script.module.pysqlite\lib;C:\Program Files (x86)\XBMC\system\python\DLLs;C:\Program Files (x86)\XBMC\system\python\Lib;C:\Program Files (x86)\XBMC\python26.zip;C:\Program Files (x86)\XBMC\system\python\lib\plat-win;C:\Program Files (x86)\XBMC\system\python\lib\lib-tk;C:\Program Files (x86)\XBMC;C:\Program Files (x86)\XBMC\system\python;C:\Program Files (x86)\XBMC\system\python\lib\site-packages;
13:39:56 T:2712   DEBUG: XBPyThread::Process - Entering source directory C:\Program Files (x86)\Mozilla Firefox
13:39:56 T:1852   DEBUG: ### [Qlock] - Delaying 3 secs
13:39:56 T:2712  NOTICE: Starting script RunIE.py
13:39:56 T:2712  NOTICE: subprocess.Popen(C:\Program Files (x86)\Mozilla Firefox irefox.exe)
13:39:56 T:2712    INFO: -->Python script returned the following error<--
13:39:56 T:2712   ERROR: Error Type: <type 'exceptions.WindowsError'>
13:39:56 T:2712   ERROR: Error Contents: [Error 2] The system cannot find the file specified
13:39:56 T:2712   ERROR: Traceback (most recent call last):
                                              File "C:\Program Files (x86)\Mozilla Firefox\launcher2.py", line 8, in <module>
                                                child = subprocess.Popen(processname)
                                              File "C:\Program Files (x86)\XBMC\system\python\Lib\subprocess.py", line 623, in __init__
                                                errread, errwrite)
                                              File "C:\Program Files (x86)\XBMC\system\python\Lib\subprocess.py", line 833, in _execute_child
                                                startupinfo)
                                            WindowsError: [Error 2] The system cannot find the file specified
13:39:56 T:2712    INFO: -->End of Python script error report<--
13:39:56 T:2712    INFO: Python script stopped
13:39:56 T:2712   DEBUG: Thread XBPyThread 2712 terminating
13:39:56 T:2340   DEBUG: waiting for python thread 10 to stop
13:39:56 T:2340   DEBUG: python thread 10 destructed
13:39:56 T:2340   DEBUG: ------ Window Init (DialogKaiToast.xml) ------

i did notice just before the script fails it tries to read an incorrect file.
Code:
13:39:56 T:2712  NOTICE: subprocess.Popen(C:\Program Files (x86)\Mozilla Firefox irefox.exe)

it seems odd. like it just got rid of \f. Reading the rest of the log it points to subprocess.py. Just to be safe, i checked to make sure that file was located in the correct directory, and it was. I suppose it could be corrupted but i would not know how to tell and/or fix it. And here's a copy of the python script im using
Code:
import subprocess

print "Starting script RunIE.py"

# Open IE and wait for it to exit
processname = "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
print "subprocess.Popen(" + processname + ")"
child = subprocess.Popen(processname)
rc = child.wait()

# Run XBMC again: this will simply set the focus back to the current instance
child = subprocess.Popen("C:\Program Files (x86)\XBMC\XBMC.exe")

so i have no clue at this point. Just keep in mind though i will not have this pointing to the firefox.exe. it will be pointing to my autoit launcher named launch.exe. I don't believe it would make a difference but im using firefox.exe for the moment just to make sure that file structure and all is working.
Aaaaaaaaaaaaaaaaaaaaaahhhhhhhh!

The backslash is an escape character in Python so you need to double them.

Code:
processname = "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"


It was pure chance that in my example none of the backslashes were valid escape sequences so they weren't being converted to other characters.
Thank you much jhsrennie. The double backslash worked perfectly.

one step closer to my perfect htpc