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

Author Topic: Event handling C# (single keypress inputs)  (Read 9250 times)

0 Members and 1 Guest are viewing this topic.

stuart88

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Event handling C# (single keypress inputs)
« 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.

stuart88

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: Event handling C# (single keypress inputs)
« Reply #1 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

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Event handling C# (single keypress inputs)
« Reply #2 on: September 26, 2017, 06:31:35 pm »

arthurmarsh

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Event handling C# (single keypress inputs)
« Reply #3 on: December 27, 2018, 12:24:47 pm »
Check here, more on...C# Key events