PDA

View Full Version : track key pressed - listen keys


Aifos
04-15-2008, 02:32 AM
Hi!
does anybody knows how to call actions when any key is pressed, not just directions keys.
I mean, if i press letter M i want a "Map" to be displayed.

i need this for a project... is it posible to do it with FPP (donґt think so)
is it posible to develople a plug in with that function?
if plugins Gurus arround here may consider this a good functionality to develope ;) , i will appreciate that!

or Denis may consider this as a feature?

think this could be good for people with Disabilities

bye!

zleifr
04-15-2008, 09:09 PM
You'd have to do it with a plugin. Almost all the relevant code is already floating around the forum. You'd just need the "standard" plugin structure and add a KeyboardEvent event listener, and a handler function that checks which key has been pressed and directs execution to the proper place.

Zephyr

Aifos
07-03-2008, 04:58 PM
Hi all!
iґm still working in this plugin wich needs to listen a keyboard event and do something...
i need that when i press key "a" (or anyone), the autorrotator plugin be disable.

So, i followed Zleifr tutorial for making a plugin (http://www.flashpanos.com/tutorials/zephyr/understanding-basic-flash-panorama-player-plugin-architecture) and also asked him by mail about this plugin iґm trying to make [thank you so much Zleifr for all you contributions] but i still cannot figure out whatґs going on... i didnґt want to bother Zleifr again...

This is what he has writen on his answer:
To communicate between plugins, you will use something like this:

In plugin 1:
hotspots.execute("externals.plugin2.disable=1");

Or in plugin 2:
hotspots.execute("externals.plugin1.disable=1");

This will send the command to the hotspots plugin's execute function, and from there it will be sent to the other plugin. It will be received in the setAttribute function, so you will need to watch for a message with name=="disable" and if the value=="1" then you will need to execute whatever code is necessary to disable the plugin.

Zephyr
and this:
That won't work fullscreen (flash security restriction), just so you know.

I attached some code from PanoSalado that illustrates using a keyboard event (amongst other things). So all you need to do after the keyboard event is set up is use:
hotspots.execute("external.autorotator.disable=1"); (or whatever the FPP command is to disable the autorotator

Zephyr

so with this said, i tryed doing the following: i included to the basic plugin structure provided by Zleifr, the function that listens keyevent and if key "a" is pressed, this is the action: hotspots.execute("external.autorotator.disable=1")

here are te codes:

// this function is called by the timer when hotspots.swf is loaded and defines the hotspots variable:
function waitHotspots (event:Event) {
if (panoController.externals.hotspots!=null) {
// wait for XML parsing
if (panoController.externals.hotspots.ready) {
waitTimer.stop();
waitTimer = null
hotspots = panoController.externals.hotspots;
// this is a good place to call a function of your own that starts doing whatever your plugin should do.

hotspots.stage.addEventListener( KeyboardEvent.KEY_DOWN, keylistener, false, 100, true );

function keylistener(event:KeyboardEvent):void
{
if (event.keyCode==65){

hotspots.execute("external.autorotator.disable=1");

}
}

}
}
}


i wonder if somebody can figure out what is going on... i think it should be working, but i donґt know why it doesnґt!...
iґd really appreciate somebody helps me with this,

many thanks

cheathamlane
07-03-2008, 06:24 PM
Aifos:

First question: does it work if, say, you put the event listener on one of your FPP hotspots (so that when the hotspot is clicked it does your function)?

If so, then it is working, almost.

What if you try this?:


// this function is called by the timer when hotspots.swf is loaded and defines the hotspots variable:
function waitHotspots (event:Event) {
if (panoController.externals.hotspots!=null) {
// wait for XML parsing
if (panoController.externals.hotspots.ready) {
waitTimer.stop();
waitTimer = null
hotspots = panoController.externals.hotspots;
// this is a good place to call a function of your own that starts doing whatever your plugin should do.

hotspots.stage.addEventListener( KeyboardEvent.KEY_DOWN, keylistener, false, 100, true );
}
}
}
//
function keylistener(event:KeyboardEvent):void
{
if (event.keyCode==65){

hotspots.execute("external.autorotator.disable=1");

}
}

Aifos
07-03-2008, 09:14 PM
hi Patrick
thanks for reply!

if i put in a hotspot: onclick="external.autorotator.disable=1"
of course, it works... if that is what you mean.

i also tryed to put my function out of the waitHotspots function... doesnґt work. :confused:

thanks again!!! =)

Aifos
07-03-2008, 10:51 PM
hey!!! it is solved!!!! =)
i wrote the function worng!!! there was a "d" missing

"external.autorotator.disabled=1"

it is working perfect!!!1

thanks Zleifr and Patrick!

i hope this can help somebody else =)

i love thi forum!

fritsjan
05-09-2011, 01:09 PM
Hi Aifos/Patrick,

I am trying to get this to work too. I have it working, but somehow it stops working when in fullscreen mode. When going back too normal mode it works again.

has this something to do with the hotspots.stage.addEventListener ?
Or with the hotspots not accessible in fullscreen?

Does your plugin works in fullscreen mode? If so can you send me the code so I can figure out what is different with mine?

Thanks in advance...

Frits Jan

Trausti Hraunfjord
05-09-2011, 07:00 PM
Fullscreen is off limits for many things... such as keyboard keys. This is due to Adobe Security concerns, and can not be circumvented.