Adam's Lair Forum

game development and casual madness
It is currently 2017/04/25, 12:35

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Keyboard typing
PostPosted: 2017/04/04, 13:09 
Junior Member
Junior Member

Joined: 2017/02/05, 13:06
Posts: 27
Role: Hobbyist
I'm not sure I understand how I could handle keyboard typing. So far all of the keyboard input I've been using is "check if this specific key was hit, released, or held down" but there is a console in my game where the user will type in commands. I would like to say "whatever key the player just hit, send it to the console"

I see that I can add event handlers to KeyDown which is one way but I'm not sure if that makes use of DualityApp.Keyboard.CharInput (in-fact I really don't know how I'm supposed to make use of that variable). Also nothing in the event args gives me the character of the key which was hit, though I could maybe manually map between the Duality.Input.Key and an ASCII value. But I feel like there is an easier way that I'm overlooking.


Top
 Profile  
 
 Post subject: Re: Keyboard typing
PostPosted: 2017/04/04, 17:11 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 1948
Location: Germany
Role: Professional
As you stumbled upon, Keyboard input in Duality comes in two flavors: Keys and chars. You probably guessed it, but mapping between the two is an incredibly complex endeavor that I would not recommend - it starts with control keys (Shift, Alt) but doesn't stop at handling different keyboard layouts (QWERTY, QWERTZ, etc.), as well as user-defined custom mappings in the operating system.

So instead, you'd in fact use DualityApp.Keyboard.CharInput when you want to know what text a user types vs. which key they pressed. Every frame, the returned string contains the sequence of characters that was entered since last update. You can use it like this and observe the code in action when you install the input handling sample package via Duality package manager.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
 Post subject: Re: Keyboard typing
PostPosted: 2017/04/05, 12:59 
Junior Member
Junior Member

Joined: 2017/02/05, 13:06
Posts: 27
Role: Hobbyist
ah so it is that simple then. I guess when I was looking at Keyboard.CharInput it always looked like an empty string in the debugger when hitting a breakpoint but maybe that was a quirk of how visual studio timed hitting the breakpoint.

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group