SFML community forums

Bindings - other languages => C => Topic started by: finaiized on December 07, 2010, 01:58:43 am

Title: Getting keyboard input
Post by: finaiized 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.
Title: Getting keyboard input
Post by: finaiized 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.