Page 1 of 1

Manipulating the interface through key presses and events

Posted: Mon Oct 19, 2009 12:46 pm
by unteer
Hello Everybody,

My first post/thread has gone so well in under 24 hours, that I have decided to start another one, slightly related, but different enough to warrant a new topic.

My research into the inner workings of Oolite has been minimal in the grand scheme of things, but I want to clarify some of my findings, so anyone willing to help would be greatly appreciated.

First off, are we unable to handle key press events in the javascript engine? I have poured over certain areas of the documentation to no avail, and sadly google is also of little help. Basically, is there a way to trigger a script based simply on a keypress such as hitting the ENTER key. I can understand why this might be difficult and conflict with the key events already in place.

If this is not the case, how are interface manipulating scripts handled. I know that the HyperRadio OXP scripts in a listener for a dance between F7 and F1. Must all listeners be this way, triggered by obscure dance maneuvers over key presses that log global events?

Is it possible to modify the keyconfig plist and construct new events for which your script can listen?

I would like to take a crack at the oolite source code, but my internet connection (being in africa) does not allow such luxury as downloading large (>3 MB) files. Maybe later.

Thoughts?

Cheers!

Posted: Mon Oct 19, 2009 1:01 pm
by another_commander
Brief answer is that no, we cannot handle keypress events from within Oolite's JavaScript API. I believe the best that can be done is check for some specific keypresses indirectly, using the switch screens events, in a way similar to what you refer to as keyboard dance. I think there could also be some security related concerns if we somehow allow keypress events to be triggered. Anyway, the current SpiderMonkey does not give us this capability.

Posted: Mon Oct 19, 2009 1:13 pm
by Commander McLane
Hi, unteer! And first of all welcome to the boards, and of course to this great game! :D

And let me take this opportunity to extend a special welcome to another East African resident! :D :D :D (I am located roughly 900 km west-north-west from you).

To your question: No, there is currently no way to detect keypresses by script, and AFAIK there are no plans into that direction. (EDIT: a_c beat e to that one.) Only the engine itself can handle keypresses. One reason is that so many of us scripters would like to get our hands on keypress-listening, but who would decide to which new functions the (rare) spare keys would be assigned? And who would sign the "Sorry, your request for a keypress was the 15th, but we have only 14 keys at our disposal."-letters?

Therefore there are only workarounds. One used by some scripts is to create a pylon-mounted special equipment, which, if fired like a missile, causes the script to do what you want. Drawback: Each of this quasi-keypresses costs the player one of his valuable missile pylons.

The other workaround is more elegant: convince the developers to include your functionality into the next release of Oolite itself (has happened before, in case of the Advanced Navigational Array; or with the yaw-keys). :wink: Although that ain't easy, of course.

Posted: Mon Oct 19, 2009 1:38 pm
by unteer
thanks everyone again for being so helpful. I have been pleasantly suprised by the friendliness of the folks on these boards and in the cOomunity. I just won't mention operating systems here because that seems to evoke ire in even the best of us on the web, no matter the circumstances.

So Oolite runs Spidermonkey eh? A complete version of it or modularized? Duly noted :)

On the note of the missiles, and sorry that this is a total newb question, but can you select which missile to fire? I am not completely opposed to this method, but in general i don't think my system is going to work anyways if there is zero way to intercept key presses.

Posted: Mon Oct 19, 2009 1:42 pm
by Commander McLane
unteer wrote:
On the note of the missiles, and sorry that this is a total newb question, but can you select which missile to fire?
Yes, if you have bought the Multi Targeting System (vanilla Oolite equipment item).

Posted: Mon Oct 19, 2009 1:44 pm
by another_commander
unteer wrote:
So Oolite runs Spidermonkey eh? A complete version of it or modularized? Duly noted :)
A complete version of SpiderMonkey 1.7 is used, with the following specifications:
1) JS_C_STRINGS_ARE_UTF8 is defined.
2) MOZILLA_1_8_BRANCH is not defined.
3) JS_THREADSAFE is not defined.

Posted: Mon Oct 19, 2009 1:49 pm
by Diziet Sma
unteer wrote:
I just won't mention operating systems here because that seems to evoke ire in even the best of us on the web, no matter the circumstances.
Hi unteer, and welcome to the boards! So far as operating systems go, we have Macintosh, WinPC and Linux users all happily co-existing and, surprising as it may seem, actively co-operating and assisting each other.. so feel free to mention OS if you see fit... :D

Posted: Mon Oct 19, 2009 1:59 pm
by Disembodied
Diziet Sma wrote:
So far as operating systems go, we have Macintosh, WinPC and Linux users all happily co-existing and, surprising as it may seem, actively co-operating and assisting each other.. so feel free to mention OS if you see fit... :D
Yes, it's the Commodore 64 – ZX Spectrum feuds you've got to watch out for! :D

Posted: Mon Oct 19, 2009 2:01 pm
by DaddyHoggy
unteer wrote:
thanks everyone again for being so helpful. I have been pleasantly suprised by the friendliness of the folks on these boards and in the cOomunity. I just won't mention operating systems here because that seems to evoke ire in even the best of us on the web, no matter the circumstances.

So Oolite runs Spidermonkey eh? A complete version of it or modularized? Duly noted :)

On the note of the missiles, and sorry that this is a total newb question, but can you select which missile to fire? I am not completely opposed to this method, but in general i don't think my system is going to work anyways if there is zero way to intercept key presses.
Quite the contrary here - Oolite started on a Mac and was ported to Linux and PC - lots of people discover quirks in Oolite caused by one OS/Platform but not found in the others (tricky for one OS oxp developers) and different OS users usually dive in to beta test for OXP creators.

Me, I run Oolite on XP, Vista, Ubuntu (Gutsy and Jaunty) - in my 3 years on the board (ok, I had a year off in the middle!) I've never seen any flaming concerning OS or platform and even the vaguest of trolling is done in jest or is very quickly squished.

So fear not, the only things that get BBQ'd here are trumbles and spammers.

Posted: Mon Oct 19, 2009 2:09 pm
by Diziet Sma
Disembodied wrote:
Diziet Sma wrote:
So far as operating systems go, we have Macintosh, WinPC and Linux users all happily co-existing and, surprising as it may seem, actively co-operating and assisting each other.. so feel free to mention OS if you see fit... :D
Yes, it's the Commodore 64 – ZX Spectrum feuds you've got to watch out for! :D
Not to mention the "BBC: the original and the best" proponents! 8)

Posted: Mon Oct 19, 2009 7:04 pm
by Kaks
<OT>
Disembodied wrote:
Yes, it's the Commodore 64 – ZX Spectrum feuds you've got to watch out for! :D
Speccy forever!!!one!!!1one!!!

PS: My only regret is never to have driven a C5! :)

PPS: Normal transmissions will be resumed shortly.
</OT>

Posted: Mon Oct 19, 2009 7:48 pm
by Chrisfs
Commander McLane wrote:
unteer wrote:
On the note of the missiles, and sorry that this is a total newb question, but can you select which missile to fire?
Yes, if you have bought the Multi Targeting System (vanilla Oolite equipment item).
Even with out that pressing 'Y' allows you to cyle through missles in order to choose which will be fired next.

Posted: Thu Oct 22, 2009 8:13 am
by unteer
thanks all for the helpful replies. Will see if this can be worked into a system somehow.