Page 1 of 1

Using KeyPress in Zxpression

Posted: Wed Jul 16, 2014 10:55 pm
by Imerion
I have searched around a bit for this but haven't found an answer.
Can I use standard KeyPresses from code somehow? As my touchEvens are processed purely in a Zexpression, I thought I might as well list standard keyboard input there as well for consistency. If its not possible the normal way with KeyPress components work very well as it is. Just curious. :)

Re: Using KeyPress in Zxpression

Posted: Thu Jul 17, 2014 10:28 am
by Kjell
Hi Imerion,
Imerion wrote:Can I use standard KeyPresses from code somehow? As my touchEvens are processed purely in a Zexpression, I thought I might as well list standard keyboard input there as well for consistency.
The way it is right now isn't very consistent / intuitive yes. The keyboard can only be accessed using the KeyPress component and doesn't have any script equivalent, while with the touchscreen it's the other way around ( only available from scripts, no component equivalent ).
Imerion wrote:If its not possible the normal way with KeyPress components work very well as it is.
However, you can implement this quite easily yourself. Simply use a Repeat component with a KeyPress inside, grab a key code from a "key map" each loop and store the results in a array. Then using a ZLibrary you can wrap accessing the array into something a little more readable if you want :wink:

Attached is a example that contains GetKey / GetKeyUp / GetKeyDown functions ( use WASD keys to demo ).

K

Posted: Thu Jul 17, 2014 2:35 pm
by Imerion
I see, smart! Thanks again for help and example! :)