Sure, you can do tha with JavaScript...
Here's a JavaScript file that I called keycode.js. I put this file into /www/profoundui/htdocs/profoundui/userdata/custom/js. If you're running your programs inside of Genie, you'd also need to put a script tag in your start.html to tell Genie to load the file. Here's the contents:
Code: Select all
var keycode_handler = {
registered: false
};
keycode_handler.keydown = function (e) {
e = e || window.event;
var handled=false;
if (e.ctrlKey) {
switch (e.keyCode) {
case 77: // M key
keycode_handler.click("button1");
handled=true;
break;
case 79: // O key
keycode_handler.click("button2");
handled=true;
break;
case 85: // U key
keycode_handler.click("button3");
handled=true;
break;
}
}
if (handled) preventEvent(e);
}
keycode_handler.click = function (widget) {
if (getObj(widget) != null)
pui.click(widget);
}
keycode_handler.start = function () {
if (keycode_handler.registered) keycode_handler.stop();
addEvent(pui.runtimeContainer, "keydown", keycode_handler.keydown);
keycode_handler.registered = true;
}
keycode_handler.stop = function () {
removeEvent(pui.runtimeContainer, "keydown", keycode_handler.keydown);
keycode_handler.registered = false;
}
The way this works is that the "addEvent" API will tell the browser to call a routine when a certain event occurs. In this case, the event is the "keydown" (key on the keyboard is pressed down) event. I've registered it to the pui.runtimeContainer -- which is the part of the screen that all of the Profound UI widgets are drawn inside. When a key is pressed, it calls the "keycode_handler.keydown" routine.
This keydown routine checks to see whether the M, O or U key is pressed while the ctrlKey is also pressed. This tells us that the user pressed Ctrl-M, Ctrl-O or Ctrl-U, respectively. The code will then use the pui.click() API to click different buttons on the screen (you'll want to change them) based on which key was pressed. So Ctrl-O, for example, clicks a button with the id "button2". You would, of course, need to create a screen with teh appropriate buttons on them, and bind the button's "response" property to set an indicator that you can check inside your RPG programs.
The preventEvent() API tells the browser that we handled the key board event, so that it does not pass the event further up. for example, in firefox Ctrl-O usually opens the "open file" dialog... but because I did preventEvent when ctrl-O is pressed, it will not open the dialog, since I'm telling it that I've handled the event.
Once this code is loaded into your session, you will need to modify the screens that use it to call keyboard_handler.start() when they want to allow these keys to be pressed, or keyboard_handler.stop() to turn them off. I'm guessing you'll want them enabled when certain screens are loaded, so you'd probably do it in the onload and onsubmit events of your screen.
Code: Select all
onload: keyboard_handler.start();
onsubmit: keyboard_handler.stop();
You can use these from any/all screens you want... If the buttons are present on the screen, it'll click them. If not, it won't do anything when the keys are pressed...
Here's a site where you can test different keypresses to see what the JavaScript keycodes would be:
http://www.cambiaresearch.com/articles/ ... -key-codes
You can learn more about the addEvent API here:
http://www.profoundlogic.com/docs/pages ... Id=3276841
The removeEvent API is here:
http://www.profoundlogic.com/docs/pages ... Id=3276843
the pui.click API is here:
http://www.profoundlogic.com/docs/pages ... Id=3276856
the getObj API is here:
http://www.profoundlogic.com/docs/pages ... Id=3276807
Any questions, just ask...