Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Keyboard Input .net Style  (Read 2947 times)

0 Members and 1 Guest are viewing this topic.

Kayy

  • Newbie
  • *
  • Posts: 2
    • View Profile
Keyboard Input .net Style
« on: October 17, 2012, 01:53:03 am »
I'm having some trouble dealing with input handling and SFML conceptually.

All of the documentation and references I can find describe a standard while loop that polls for events, but the .net bindings use DispatchEvents(). From what I can gather, this does all of the event polling internally to promote similarity with .net coding and design conventions.

But I'm not understanding how the approach is used in a c# SFML program. Does DispatchEvents() poll for any events on its own every time it's called in a loop? Can I register event handlers directly to them (i.e. OnKeyPress += new EventHandler(OnKeyPress)) to define how input will be processed?

I feel like this must be a pretty basic question, as it doesn't seem to have given anyone else on the internet any trouble. But I've not had any luck finding documentation for the .net binding, and experimenting to find out how it executes the functions documented for vanilla SFML sounds exhausting.

[edit]

I think my initial post was unclear. My program has a single RenderWindow which can display any one of multiple screens at a time.

My current plan is to set up an event handler in the main program (where the while loop that calls DispatchEvents() is), register the RenderWindow's KeyPressed event to it, and then execute the OnKeyPressed function each time the KeyPressed event fires. The OnKeyPressed function itself calls a function of the currently active screen (HandleInput) which takes the key code that fired the event as an argument. The active screen then parses the input on its own.

I'm pretty confident that this approach will work, but I'm not sure how "good" of an approach it is. Are there any aspects of SFML/c# that I'm missing or complicating by doing things this way?
« Last Edit: October 17, 2012, 02:49:11 am by Kayy »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Keyboard Input .net Style
« Reply #1 on: October 17, 2012, 07:44:03 am »
I don't really understand your "problem". Event handling in SFML.Net uses standard .Net events, so there's no new concept to learn, and there are the documentation and examples that show how it works in case you're not sure.

So...?
Laurent Gomila - SFML developer

Kayy

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Keyboard Input .net Style
« Reply #2 on: October 17, 2012, 08:15:18 pm »
Hello Laurent, and thank you for your reply.

Re-reading my post again, I see that I did a poor job of describing my issue. I'm not having a problem with the .Net binding of SFML but rather with weak overall programming skills. Coding I've done in the past didn't rely on events for keyboard input and I'm struggling with understanding how to use events properly; once I have a better grasp of that I'm confident that I will have no issues using the SFML for input.

I'll look through the example programs that come with the library for a demonstration, and hopefully it'll be easy to see where I've been going wrong.


[edit]

In the examples folder of the 2.0 download, all that I see are .exe files, and I don't know how to (or if I can) look at the code for those in a compiler. Is there another place where example code is stored so that I can look at it?

[re-edit]

Nevermind, I found the examples in GitHub, and they do clear up my confusion. And I forgot to say it previously, but thank you for your work on SFML Laurent, I've enjoyed using it so far.
« Last Edit: October 19, 2012, 01:45:25 am by Kayy »

 

anything