SFML community forums

Bindings - other languages => DotNet => Topic started by: stuart88 on September 26, 2017, 08:42:45 am

Title: Event handling C# (single keypress inputs)
Post by: stuart88 on September 26, 2017, 08:42:45 am
I can't get my head around how to deal with single keypress inputs using the .NET (C#) version of SFML.

I previously used the C++ version and was fine with the
window.pollEvent()
method, but I can't do that with .NET, or at least I can't figure out how to do it.

Could someone write a quick thing to demonstrate how I would read a single keyboard input and make it do something?

Many thanks.
Title: Re: Event handling C# (single keypress inputs)
Post by: stuart88 on September 26, 2017, 09:11:40 am
Never mind, figured it out  :D

A bit of deeper searching gave me this:

window.KeyPressed += OnKeyPressed

void OnKeyPressed(object sender, SFML.Window.KeyEventArgs e)
            {
                if (e.Code == Keyboard.Key.A)
                {
                    // DO STUFF
                }
            }

All inside this part:
static void Main()
{
      // CODE HERE
}
Works a treat.

 :D
Title: Re: Event handling C# (single keypress inputs)
Post by: dabbertorres on September 26, 2017, 06:31:35 pm
For future reference: https://github.com/SFML/SFML.Net/tree/master/examples
Title: Re: Event handling C# (single keypress inputs)
Post by: arthurmarsh on December 27, 2018, 12:24:47 pm
Check here, more on...C# Key events (http://csharp.net-informations.com/gui/key-press-cs.htm)