KeyHit in WinRT topic

Monkey Targets Forums/Windows 8/KeyHit in WinRT topic

The KiwiGeek(Posted 2014) [#1]
Hi everyone,

I must be missing something obvious. No matter what I do, I can't get KeyHit to register in a WinRT/Win8 target. For instance:

Import mojo

Class MyApp Extends App
Method OnCreate()
SetUpdateRate(60)
End

Method OnUpdate()
If KeyHit(KEY_ENTER) Then EndApp
End

Method OnRender()
Cls
SetColor(255,255,255)
DrawText("Waiting...", 320, 240, 0)
End
End

Function Main()
New MyApp
End

While that works fine (just waiting for a keypress) with HTML5 and Desktop, on the Windows 8 target it never registers the keypress to quit. I'm using Visual Studio 2013 to open the solution after building in monkey, to then debug against my local machine.


Leginus(Posted 2014) [#2]
Check that it is definitely not the keypress that isn't working by changing your "Then EndApp" to something else e.g. changing a flag in your code and printing drawing some text to screen, as I am not sure that you can actually end a winrt app (or shouldn't) as this is system controlled.....I could be wrong (and frequently am).


dopeyrulz(Posted 2014) [#3]
You can't end a WinRT 'metro' app. So your key is being processed most likely. As per iOS/WP8 the apps go to 'sleep' (in the background when you move to another app) and will be killed off by the system as required. You can kill the app dragging down to the bottom.

Hope that helps.


The KiwiGeek(Posted 2014) [#4]
Thanks guys - I guess I chose a really bad example to show it wasn't working - I was just trying to do something simple :)

The problem exists for me across multiple projects - if I take that code from above, and add a flag indicating hit count, I still don't get any change (in count) on WinRT when I hit enter vs it working as I would expect on Desktop:

Import mojo

Class MyApp Extends App

Field HitCount:Int = 0

Method OnCreate()
SetUpdateRate(60)
End

Method OnUpdate()
If KeyHit(KEY_ENTER) Then HitCount += 1
End

Method OnRender()
Cls
SetColor(255,255,255)
DrawText("Hit " + HitCount + " times", 320, 240, 0)
End
End

Function Main()
New MyApp
End

I just don't get it. Hopefully I'm missing something mindbogglingly obvious about WinRT targets.