Using KeyPress in Zxpression

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
Imerion
Posts: 197
Joined: Sun Feb 09, 2014 4:42 pm

Using KeyPress in Zxpression

Post by Imerion » Wed Jul 16, 2014 10:55 pm

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. :)

User avatar
Kjell
Posts: 1669
Joined: Sat Feb 23, 2008 11:15 pm

Re: Using KeyPress in Zxpression

Post by Kjell » Thu Jul 17, 2014 10:28 am

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
Attachments
Keys.zgeproj
(3.58 KiB) Downloaded 115 times

Imerion
Posts: 197
Joined: Sun Feb 09, 2014 4:42 pm

Post by Imerion » Thu Jul 17, 2014 2:35 pm

I see, smart! Thanks again for help and example! :)

Post Reply