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

Author Topic: Getting keyboard input  (Read 5413 times)

0 Members and 1 Guest are viewing this topic.

finaiized

  • Newbie
  • *
  • Posts: 4
    • View Profile
Getting keyboard input
« on: December 07, 2010, 01:58:43 am »
I'm using SFML's C Binding, and I'm trying to get input from the keyboard.
Code: [Select]
while (sfRenderWindow_IsOpened(App))
    {
        while (sfRenderWindow_GetEvent(App, &Event))
        {
            Input = sfRenderWindow_GetInput(App);
            if (Event.Type == sfEvtClosed)
                sfRenderWindow_Close(App);
            if (Event.Type == sfEvtKeyPressed) {
            if (sfInput_IsKeyDown(Input, sfKeyCode.sfKeyA)) {
            sfRenderWindow_Close(App);
           
            }
        }


I have the above code right now, but looking at the C++ tutorials, and the API, I have a feeling that I should either use Event.Type == sfEvtKeyPressed OR sfInput_IsKeyDown. This leads me to two questions:

1) Which way should I use in a game loop?
2) If it is using Event.Type == sfEvtKeyPressed, what code do I use to check the contents of Event for a key?

Thanks for your time!  :o  I've been trying everything and I'm guessing it isn't too hard but it isn't hitting me.

finaiized

  • Newbie
  • *
  • Posts: 4
    • View Profile
Getting keyboard input
« Reply #1 on: December 07, 2010, 04:48:14 am »
Looks like I overlooked something, the answer is quite simple! In the while loop for GetEvent(),

Code: [Select]
        if (Event.Type == sfEvtKeyPressed) {
        if (Event.Key.Code == sfKeyA) {
        sfRenderWindow_Close(App);
        }

will hook on to the Key A.

 

anything