Using KeyPress in Zxpression

All topics about ZGameEditor goes here.

Moderator: Moderators

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

Using KeyPress in Zxpression

Post 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. :)
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: Using KeyPress in Zxpression

Post 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
Attachments
Keys.zgeproj
(3.58 KiB) Downloaded 395 times
Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

Post by Imerion »

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