Why does'nt work ? (key pressed)

Hi,

I don’t understand why my code does’nt work. (no error, just no effect)

function onKeyEvent(event) print("touche pressé") if (event.keyName == "a") and (event.phase == "down") then joueur.niveau = joueur.niveau + 1 print(jouer.niveau) end end Runtime:addEventListener( "key", onKeyEvent )

Are you getting your print messages in your console log?  

What device are you running the code on (simulator? Actual device?)

What version of Corona are you using?

Rob

Hello sir,

  • No message in console

  • Device: simulator iphone 6

  • Version: 2016.2924 (2016.7.30)

Best regards

The iPhone simulator skins do not register key events.

Update: documentation - https://docs.coronalabs.com/api/event/key/index.html#TOC

Actually desktop keys should work in the simulator regardless of the skin. There are no key events on iOS devices which would include the Xcode Simulator, but the Corona simulator does get them.

You have an error in your code that’s causing an error. These errors should be displaying in the simulator’s console window (unless you’re using and IDE that’s taking the simulator output). 

 joueur.niveau = joueur.niveau + 1 print(jouer.niveau)

You’re trying to print jouer which is not the table value you’re updating which is joueur.

Now your print statement that prints: touche pressé should have shown up in your console log just before the error message. This leads me to wonder if you’ve done something to disable the error messages like creating a global variable named “debug” or “print”.

Rob

You should file a bug then, Rob, because I’ve never been able to get key events in iOS simulator skins!

Alex are you using Windows or macOS? 

I normally use Windows, but just fired up my Macbook and tested and, yes indeed, key strikes are being registered there.

So, I guess I missed the “gotcha” about keys not working in iOS skins on Win. My bad!

To the original poster…@gaelsev, are you using Corona on Windows or on macOS?

Rob

Hi,

Sorry for the late and thank you for your support.

But print(jouer.niveau) is not the problem, if i remove this line, it’s doesn’t work also.

I’m playing corona on Windows 10 x64

Do not remove it, replace it with print(joueur.niveau), you were missing a ‘u’.

The problem is that key events don’t register for iOS simulator skins on Windows, as discussed above.

@sdktester15

Yes i know bro but is not the probleme.

I dont understand why events key is not working on simulator, why you dont fix this ? I must to build .exe to try the program is not good :confused:

Alex explained this above.

The simulator on Windows looks at the skin to determine features. When it sees iOS, it says “iOS doesn’t support key events” so it doesn’t make them available to the simulator. To solve this, you simply need to change skins in the simulator to something not iOS related.

Rob

Oki sorry a didnt understand it like that because my language is french.

I will try another skin thx u

I tried with another skin, it’s work. Thank you.

Are you getting your print messages in your console log?  

What device are you running the code on (simulator? Actual device?)

What version of Corona are you using?

Rob

Hello sir,

  • No message in console

  • Device: simulator iphone 6

  • Version: 2016.2924 (2016.7.30)

Best regards

The iPhone simulator skins do not register key events.

Update: documentation - https://docs.coronalabs.com/api/event/key/index.html#TOC

Actually desktop keys should work in the simulator regardless of the skin. There are no key events on iOS devices which would include the Xcode Simulator, but the Corona simulator does get them.

You have an error in your code that’s causing an error. These errors should be displaying in the simulator’s console window (unless you’re using and IDE that’s taking the simulator output). 

 joueur.niveau = joueur.niveau + 1 print(jouer.niveau)

You’re trying to print jouer which is not the table value you’re updating which is joueur.

Now your print statement that prints: touche pressé should have shown up in your console log just before the error message. This leads me to wonder if you’ve done something to disable the error messages like creating a global variable named “debug” or “print”.

Rob