Detect keystroke for windows build?

Im thinking of making my first desktop app and ill need this: is it possible to detect a keystroke ? like if any key is pressed then something happens?

https://docs.coronalabs.com/api/event/key/index.html

Thanks!

Also we post tutorials and such to the blog. It’s a great resource to look for things. We are currently doing a round up of previous tutorials and last week’s was on input.  You should spend some time with these:

https://coronalabs.com/blog/2015/08/04/tutorial-treasury-input-devices/

Rob

Hey @Rob would you mind writing some code? so a function and an event listener ?. so the function should detect when a key is pressed and write some thing to the console? 

A sample like that  is already available to you.  Dig through the docs:

https://docs.coronalabs.com/api/event/key/descriptor.html

Hey @roaminggamer nice talking to you again!

Ok so i tried this an it works.

local number = 0 local numberTxt = display.newText( "0", 0, 0, native.systemFontBold, 80 ) numberTxt.x = display.contentCenterX numberTxt.y = 100 local function updateNumber(event) number = number + 1 numberTxt.text = string.format("%d", number ) end Runtime:addEventListener( "key", updateNumber )

But when i try adding  a began or ended phase then it stoped working… like heres the code…

local number = 0 local numberTxt = display.newText( "0", 0, 0, native.systemFontBold, 80 ) numberTxt.x = display.contentCenterX numberTxt.y = 100 local function updateNumber(event) if event.phase == "began" then number = number + 1 numberTxt.text = string.format("%d", number ) end end Runtime:addEventListener( "key", updateNumber )

is it because they haven’t implemented it into lua yet or what?

@SonicX278, the entry for phases is right in the docs and explains exactly which phases are detected for keystrokes.

Don’t take my tone as aggressive or angry; I’m trying to illustrate the fact that all of the information you are looking for is right in the docs, and researching in there is much quicker than waiting for someone to answer in a forum post (although I’m aware that this time, we’ve been pretty quick).

Oh its just im working on a fairly big game and don’t have the time to look around but ill make some time haha well thanks for everything guys!

Hey @SonixX278.  We all are busy working on big things and taking time to answer you is time consuming.  Consider…

If I write out how to do this in this forum post and I write code you can grab and use, you still have to read the forum post , understand the code and copy it. It’s not much more effort for you to click on the URL that perfectly explains what you’re looking for.

One of the main reasons we write tutorials is so that we don’t have to repeat myself. Can you imagine how many people have asked how to keep score in games? If we had to answer that every time it was asked it would be a huge waste of our time.  By writing tutorials, we write it once and when you ask we point you to what we’ve written.

We have tutorials, guides and  API documentation that all have examples. 

And for community members who do the similar, you’re also asking them to take time to write you a custom solution that is the same solution they provided last time. 

Rob

oh well alex solved my problem … but i understand i guess i need to use google more often haha

https://docs.coronalabs.com/api/event/key/index.html

Thanks!

Also we post tutorials and such to the blog. It’s a great resource to look for things. We are currently doing a round up of previous tutorials and last week’s was on input.  You should spend some time with these:

https://coronalabs.com/blog/2015/08/04/tutorial-treasury-input-devices/

Rob

Hey @Rob would you mind writing some code? so a function and an event listener ?. so the function should detect when a key is pressed and write some thing to the console? 

A sample like that  is already available to you.  Dig through the docs:

https://docs.coronalabs.com/api/event/key/descriptor.html

Hey @roaminggamer nice talking to you again!

Ok so i tried this an it works.

local number = 0 local numberTxt = display.newText( "0", 0, 0, native.systemFontBold, 80 ) numberTxt.x = display.contentCenterX numberTxt.y = 100 local function updateNumber(event) number = number + 1 numberTxt.text = string.format("%d", number ) end Runtime:addEventListener( "key", updateNumber )

But when i try adding  a began or ended phase then it stoped working… like heres the code…

local number = 0 local numberTxt = display.newText( "0", 0, 0, native.systemFontBold, 80 ) numberTxt.x = display.contentCenterX numberTxt.y = 100 local function updateNumber(event) if event.phase == "began" then number = number + 1 numberTxt.text = string.format("%d", number ) end end Runtime:addEventListener( "key", updateNumber )

is it because they haven’t implemented it into lua yet or what?

@SonicX278, the entry for phases is right in the docs and explains exactly which phases are detected for keystrokes.

Don’t take my tone as aggressive or angry; I’m trying to illustrate the fact that all of the information you are looking for is right in the docs, and researching in there is much quicker than waiting for someone to answer in a forum post (although I’m aware that this time, we’ve been pretty quick).

Oh its just im working on a fairly big game and don’t have the time to look around but ill make some time haha well thanks for everything guys!

Hey @SonixX278.  We all are busy working on big things and taking time to answer you is time consuming.  Consider…

If I write out how to do this in this forum post and I write code you can grab and use, you still have to read the forum post , understand the code and copy it. It’s not much more effort for you to click on the URL that perfectly explains what you’re looking for.

One of the main reasons we write tutorials is so that we don’t have to repeat myself. Can you imagine how many people have asked how to keep score in games? If we had to answer that every time it was asked it would be a huge waste of our time.  By writing tutorials, we write it once and when you ask we point you to what we’ve written.

We have tutorials, guides and  API documentation that all have examples. 

And for community members who do the similar, you’re also asking them to take time to write you a custom solution that is the same solution they provided last time. 

Rob