# Important SDL BUG : Keyboard and Mouse classes dont work : Please HELP!

**URL:** <https://discourse.libsdl.org/t/important-sdl-bug-keyboard-and-mouse-classes-dont-work-please-help/19076>\
**Category:** SDL Development\
**Created:** [August 21, 2012, 10:58pm UTC](https://discourse.libsdl.org/t/important-sdl-bug-keyboard-and-mouse-classes-dont-work-please-help/19076 "2012-08-21T22:58:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pablo\_Marty](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Pablo\_Marty](https://discourse.libsdl.org/u/Pablo_Marty)\
**Post date:** [August 21, 2012, 10:58pm UTC](https://discourse.libsdl.org/t/important-sdl-bug-keyboard-and-mouse-classes-dont-work-please-help/19076/1 "2012-08-21T22:58:57Z")

</div>

Hi Ladies and Guys  
?  
I have found out what my problem was: a simple, but very important SDL bug. As I had told you before, the keyboard input didn t move my character (Mario) … and I was ignoring the Events class in order to introduce multithreading to my program  
?  
I tried in a new simple program, that just tests these functions (Keyboard.IsKeyPressed(Key) and Mouse.IsButtonPressed(MouseButton))  
and they ALWAYS return false, that s they don t recognize the key press and the mouse button press  
?  
// this app never ends or crashesusingSdlDotNet;usingSdlDotNet.Graphics;usingSdlDotNet.Input;usingSystem.Drawing;namespace  
{KEYBOARDclassProgram{  
{  
{  
}  
}  
}  
}publicstaticvoidMain()Video.Initialize();Video.SetVideoMode(800, 600, 24);for( ; ; )Video.Screen.Fill(Color.Orange);Video.Screen.Update();if(Mouse.IsButtonPressed(MouseButton.PrimaryButton)) break;if(Keyboard.IsKeyPressed(Key.Escape)) break;  
?  
Can you confirm this and tell me how to solve it? It seems there are not too many list members that use C# with SDL, but I supposse and hope that someone is able to terminate with this problem … my Mario game really was getting very nice  
?  
Thank you very much  
?  
Pablo

Asesinar y comer un perro o un gato es lo mismo q hacerlo a una vaca, un pollo, un cerdo o un pez. El genocidio no discrimina. No seas complice de genocidas. No seas genocida. En la vida tarde o temprano todo vuelve. No comas cadaveres. No seas necr?fago.

---

<div class="post-metadata">

**Author:** ![Christian\_Leger](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/c/ecae2f/32.png) [@Christian\_Leger](https://discourse.libsdl.org/u/Christian_Leger)\
**Post date:** [August 21, 2012, 11:13pm UTC](https://discourse.libsdl.org/t/important-sdl-bug-keyboard-and-mouse-classes-dont-work-please-help/19076/2 "2012-08-21T23:13:33Z")

</div>

Hi,

If I were you, I’d make sure that your program still doesn’t crash or  
exit when you check for more than either the primary mouse button or  
the escape key.

I suggest you try the same program, but with every mouse button, and  
with a number of other keys (like a, b, c, etc. which shouldn’t move  
between a UK/US and latin-configured keyboard). Then mash the keyboard  
to see that really none of these work.

So for example in the keyboard-checking part (you’ll have to ensure  
correct variable/constant names):

if  
(  
Keyboard.IsKeyPressed(Key.Escape) ||  
Keyboard.IsKeyPressed(Key.Up) ||  
Keyboard.IsKeyPressed(Key.Down) ||  
…  
Keyboard.IsKeyPressed(Key.a) ||  
Keyboard.IsKeyPressed(Key.b) ||  
Keyboard.IsKeyPressed(Key.c)  
…

)  
{  
break;  
}

Finally, I’ll point out that I’m not familiar with how this C# package  
wraps SDL - it seems to test for ‘key pressed’ - does that mean the  
key must be in the ‘down’ position when that function runs? What if  
you just have quick fingers and the state of the keys is not down when  
the program checks for ‘pressed’?

Good luck!

ChristianOn Tue, Aug 21, 2012 at 6:58 PM, Pablo Marty wrote:

> Hi Ladies and Guys
> 
> I have found out what my problem was: a simple, but very important SDL bug.  
> As I had told you before, the keyboard input didn t move my character  
> (Mario) … and I was ignoring the Events class in order to introduce  
> multithreading to my program
> 
> I tried in a new simple program, that just tests these functions  
> (Keyboard.IsKeyPressed(Key) and Mouse.IsButtonPressed(MouseButton))  
> and they ALWAYS return false, that s they don t recognize the key press and  
> the mouse button press
> 
> // this app never ends or crashes  
> using  
> SdlDotNet;  
> using  
> SdlDotNet.Graphics;  
> using  
> SdlDotNet.Input;  
> using  
> System.Drawing;  
> namespace  
> KEYBOARD  
> {  
> class Program  
> {  
> public static void Main()  
> {  
> Video.Initialize();  
> Video.SetVideoMode(800, 600, 24);  
> for ( ; ; )  
> {  
> Video.Screen.Fill(Color.Orange);  
> Video.Screen.Update();  
> if (Mouse.IsButtonPressed(MouseButton.PrimaryButton)) break;  
> if (Keyboard.IsKeyPressed(Key.Escape)) break;  
> }  
> }  
> }  
> }
> 
> Can you confirm this and tell me how to solve it? It seems there are not too  
> many list members that use C# with SDL, but I supposse and hope that someone  
> is able to terminate with this problem … my Mario game really was getting  
> very nice
> 
> Thank you very much
> 
> Pablo
> 
> Asesinar y comer un perro o un gato es lo mismo q hacerlo a una vaca, un  
> pollo, un cerdo o un pez. El genocidio no discrimina. No seas complice de  
> genocidas. No seas genocida. En la vida tarde o temprano todo vuelve. No  
> comas cadaveres. No seas necr?fago.
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Pablo\_Marty](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Pablo\_Marty](https://discourse.libsdl.org/u/Pablo_Marty)\
**Post date:** [August 22, 2012, 6:17am UTC](https://discourse.libsdl.org/t/important-sdl-bug-keyboard-and-mouse-classes-dont-work-please-help/19076/3 "2012-08-22T06:17:21Z")

</div>

Hello girls and boys; Christian  
?  
Here comes the program edited as you told me  
?{  
{  
||  
||  
||  
||  
{  
}  
||  
||  
||  
{  
}  
}  
}publicstaticvoidMain()Video.Initialize();Video.SetVideoMode(800, 600, 24);for( ; ; )Video.Screen.Fill(Color.Orange);Video.Screen.Update();if(Mouse.IsButtonPressed(MouseButton.PrimaryButton)Mouse.IsButtonPressed(MouseButton.SecondaryButton)Mouse.IsButtonPressed(MouseButton.WheelUp)Mouse.IsButtonPressed(MouseButton.WheelDown)Mouse.IsButtonPressed(MouseButton.None))break;if(Keyboard.IsKeyPressed(Key.Escape)Keyboard.IsKeyPressed(Key.A)Keyboard.IsKeyPressed(Key.Space)Keyboard.IsKeyPressed(Key.Return)) break;  
?  
I was sure it wouldn t?work. Both input functions still return false, even the Mouse.IsButtonPressed(MouseButton.None), that teorethically should return true if no mouse button is pressed  
Nevertheless, Christian, I really thank you strongly, cos you were the unique member of the list that replied me, even not being used to C#  
?  
I changed the Subject of this mail in order to catch the atention of those who use SDL on C# .NET programming language  
?  
I wonder, is C#SDL library (I mean the binarys, the DLLs) the same than the C/C++ library, or the VB one, or others. I really doubt if this could be an SDL bug. Perhaps the SDL library for C/C++ hasn t this problem, and the C#'s one does …  
?  
Is there any older version of C# SDL than 6.1.1 beta, that maybe doesn t have this problem?  
?  
Could someone who uses C# (and SdlDotNet or C#SDL) tell me what to do with this? I would thank you very much

Pablo

Asesinar y comer un perro o un gato es lo mismo q hacerlo a una vaca, un pollo, un cerdo o un pez. El genocidio no discrimina. No seas complice de genocidas. No seas genocida. En la vida tarde o temprano todo vuelve. No comas cadaveres. No seas necr?[fago.De](http://fago.De): Christian Leger \<chrism.leger at [gmail.com](http://gmail.com)\>  
Para: Pablo Marty \<@Pablo\_Marty\>; SDL Development List   
Enviado: martes, 21 de agosto de 2012 20:13  
Asunto: Re: [SDL] important SDL BUG : Keyboard and Mouse classes dont work : Please HELP!!!

Hi,

If I were you, I’d make sure that your program still doesn’t crash or  
exit when you check for more than either the primary mouse button or  
the escape key.

I suggest you try the same program, but with every mouse button, and  
with a number of other keys (like a, b, c, etc. which shouldn’t move  
between a UK/US and latin-configured keyboard). Then mash the keyboard  
to see that really none of these work.

So for example in the keyboard-checking part (you’ll have to ensure  
correct variable/constant names):

if  
(  
Keyboard.IsKeyPressed(Key.Escape) ||  
Keyboard.IsKeyPressed(Key.Up) ||  
Keyboard.IsKeyPressed(Key.Down) ||  
…  
Keyboard.IsKeyPressed(Key.a) ||  
Keyboard.IsKeyPressed(Key.b) ||  
Keyboard.IsKeyPressed(Key.c)  
…

)  
{  
? ? break;  
}

Finally, I’ll point out that I’m not familiar with how this C# package  
wraps SDL - it seems to test for ‘key pressed’ - does that mean the  
key must be in the ‘down’ position when that function runs? What if  
you just have quick fingers and the state of the keys is not down when  
the program checks for ‘pressed’?

Good luck!

Christian

On Tue, Aug 21, 2012 at 6:58 PM, Pablo Marty \<@Pablo\_Marty\> wrote:

> Hi Ladies and Guys
> 
> I have found out what my problem was: a simple, but very important SDL bug.  
> As I had told you before, the keyboard input didn t move my character  
> (Mario) … and I was ignoring the Events class in order to introduce  
> multithreading to my program
> 
> I tried in a new simple program, that just tests these functions  
> (Keyboard.IsKeyPressed(Key) and Mouse.IsButtonPressed(MouseButton))  
> and they ALWAYS return false, that s they don t recognize the key press and  
> the mouse button press
> 
> // this app never ends or crashes  
> using  
> SdlDotNet;  
> using  
> SdlDotNet.Graphics;  
> using  
> SdlDotNet.Input;  
> using  
> System.Drawing;  
> namespace  
> KEYBOARD  
> {  
> class Program  
> {  
> public static void Main()  
> {  
> Video.Initialize();  
> Video.SetVideoMode(800, 600, 24);  
> for ( ; ; )  
> {  
> Video.Screen.Fill(Color.Orange);  
> Video.Screen.Update();  
> if (Mouse.IsButtonPressed(MouseButton.PrimaryButton)) break;  
> if (Keyboard.IsKeyPressed(Key.Escape)) break;  
> }  
> }  
> }  
> }
> 
> Can you confirm this and tell me how to solve it? It seems there are not too  
> many list members that use C# with SDL, but I supposse and hope that someone  
> is able to terminate with this problem … my Mario game really was getting  
> very nice
> 
> Thank you very much
> 
> Pablo
> 
> Asesinar y comer un perro o un gato es lo mismo q hacerlo a una vaca, un  
> pollo, un cerdo o un pez. El genocidio no discrimina. No seas complice de  
> genocidas. No seas genocida. En la vida tarde o temprano todo vuelve. No  
> comas cadaveres. No seas necr?fago.
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Fabio\_Panettieri](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/f/a3d4f5/32.png) [@Fabio\_Panettieri](https://discourse.libsdl.org/u/Fabio_Panettieri)\
**Post date:** [August 22, 2012, 6:51am UTC](https://discourse.libsdl.org/t/important-sdl-bug-keyboard-and-mouse-classes-dont-work-please-help/19076/4 "2012-08-22T06:51:32Z")

</div>

Hi Pablo,

I think you can get more attention if you follow some simple  
Nettiquete rules, here are a few things that made me ignore your post.

- Try to write in plain text, avoid html.

- Try to sound humble when you write, not cocky “I found this very  
important bug in SDL”, even if true can be expressed as “I think there  
is something not working here, can you help me fin what’s wrong?”.

- If others answer you, it’s because you present an interesting  
problem, and you show that you have tried all before asking for help,  
not because you are about to finish that nice Mario game.

Regarding your problem.

- C#SDL 6.1.1 is the last version as the main page says  
([http://cs-sdl.sourceforge.net/](http://cs-sdl.sourceforge.net/))  
In their forum you will probably get faster answers, out you can try  
using their chat ( although I’m not sure if it’s alive ).

- It seems to me that Keyboard events can be accessed through  
KeyboardState class (  
[http://cs-sdl.sourceforge.net/apidocs/html/class\_sdl\_dot\_net\_1\_1\_input\_1\_1\_keyboard\_state.html](http://cs-sdl.sourceforge.net/apidocs/html/class_sdl_dot_net_1_1_input_1_1_keyboard_state.html)  
)

Have you tried using that class? Did it gave you an error or something?–  
sn00py

2012/8/22 Pablo Marty :

> Hello girls and boys; Christian
> 
> Here comes the program edited as you told me
> 
> public static void Main()  
> {  
> Video.Initialize();  
> Video.SetVideoMode(800, 600, 24);  
> for ( ; ; )  
> {  
> Video.Screen.Fill(Color.Orange);  
> Video.Screen.Update();  
> if (Mouse.IsButtonPressed(MouseButton.PrimaryButton)  
> || Mouse.IsButtonPressed(MouseButton.SecondaryButton)  
> || Mouse.IsButtonPressed(MouseButton.WheelUp)  
> || Mouse.IsButtonPressed(MouseButton.WheelDown)  
> || Mouse.IsButtonPressed(MouseButton.None))  
> {  
> break;  
> }  
> if (Keyboard.IsKeyPressed(Key.Escape)  
> || Keyboard.IsKeyPressed(Key.A)  
> || Keyboard.IsKeyPressed(Key.Space)  
> || Keyboard.IsKeyPressed(Key.Return))  
> {  
> break;  
> }  
> }  
> }
> 
> I was sure it wouldn t work. Both input functions still return false, even  
> the Mouse.IsButtonPressed(MouseButton.None), that teorethically should  
> return true if no mouse button is pressed  
> Nevertheless, Christian, I really thank you strongly, cos you were the  
> unique member of the list that replied me, even not being used to C#
> 
> I changed the Subject of this mail in order to catch the atention of those  
> who use SDL on C# .NET programming language
> 
> I wonder, is C#SDL library (I mean the binarys, the DLLs) the same than the  
> C/C++ library, or the VB one, or others. I really doubt if this could be an  
> SDL bug. Perhaps the SDL library for C/C++ hasn t this problem, and the C#'s  
> one does …
> 
> Is there any older version of C# SDL than 6.1.1 beta, that maybe doesn t  
> have this problem?
> 
> Could someone who uses C# (and SdlDotNet or C#SDL) tell me what to do with  
> this? I would thank you very much
> 
> Pablo
> 
> Asesinar y comer un perro o un gato es lo mismo q hacerlo a una vaca, un  
> pollo, un cerdo o un pez. El genocidio no discrimina. No seas complice de  
> genocidas. No seas genocida. En la vida tarde o temprano todo vuelve. No  
> comas cadaveres. No seas necr?fago.  
> De: Christian Leger \<chrism.leger at [gmail.com](http://gmail.com)\>  
> Para: Pablo Marty ; SDL Development List  
>   
> Enviado: martes, 21 de agosto de 2012 20:13  
> Asunto: Re: [SDL] important SDL BUG : Keyboard and Mouse classes dont work :  
> Please HELP!!!
> 
> Hi,
> 
> If I were you, I’d make sure that your program still doesn’t crash or  
> exit when you check for more than either the primary mouse button or  
> the escape key.
> 
> I suggest you try the same program, but with every mouse button, and  
> with a number of other keys (like a, b, c, etc. which shouldn’t move  
> between a UK/US and latin-configured keyboard). Then mash the keyboard  
> to see that really none of these work.
> 
> So for example in the keyboard-checking part (you’ll have to ensure  
> correct variable/constant names):
> 
> if  
> (  
> Keyboard.IsKeyPressed(Key.Escape) ||  
> Keyboard.IsKeyPressed(Key.Up) ||  
> Keyboard.IsKeyPressed(Key.Down) ||  
> …  
> Keyboard.IsKeyPressed(Key.a) ||  
> Keyboard.IsKeyPressed(Key.b) ||  
> Keyboard.IsKeyPressed(Key.c)  
> …
> 
> )  
> {  
> break;  
> }
> 
> Finally, I’ll point out that I’m not familiar with how this C# package  
> wraps SDL - it seems to test for ‘key pressed’ - does that mean the  
> key must be in the ‘down’ position when that function runs? What if  
> you just have quick fingers and the state of the keys is not down when  
> the program checks for ‘pressed’?
> 
> Good luck!
> 
> Christian
> 
> On Tue, Aug 21, 2012 at 6:58 PM, Pablo Marty wrote:
> 
> > Hi Ladies and Guys
> > 
> > I have found out what my problem was: a simple, but very important SDL  
> > bug.  
> > As I had told you before, the keyboard input didn t move my character  
> > (Mario) … and I was ignoring the Events class in order to introduce  
> > multithreading to my program
> > 
> > I tried in a new simple program, that just tests these functions  
> > (Keyboard.IsKeyPressed(Key) and Mouse.IsButtonPressed(MouseButton))  
> > and they ALWAYS return false, that s they don t recognize the key press  
> > and  
> > the mouse button press
> > 
> > // this app never ends or crashes  
> > using  
> > SdlDotNet;  
> > using  
> > SdlDotNet.Graphics;  
> > using  
> > SdlDotNet.Input;  
> > using  
> > System.Drawing;  
> > namespace  
> > KEYBOARD  
> > {  
> > class Program  
> > {  
> > public static void Main()  
> > {  
> > Video.Initialize();  
> > Video.SetVideoMode(800, 600, 24);  
> > for ( ; ; )  
> > {  
> > Video.Screen.Fill(Color.Orange);  
> > Video.Screen.Update();  
> > if (Mouse.IsButtonPressed(MouseButton.PrimaryButton)) break;  
> > if (Keyboard.IsKeyPressed(Key.Escape)) break;  
> > }  
> > }  
> > }  
> > }
> > 
> > Can you confirm this and tell me how to solve it? It seems there are not  
> > too  
> > many list members that use C# with SDL, but I supposse and hope that  
> > someone  
> > is able to terminate with this problem … my Mario game really was  
> > getting  
> > very nice
> > 
> > Thank you very much
> > 
> > Pablo
> > 
> > Asesinar y comer un perro o un gato es lo mismo q hacerlo a una vaca, un  
> > pollo, un cerdo o un pez. El genocidio no discrimina. No seas complice de  
> > genocidas. No seas genocida. En la vida tarde o temprano todo vuelve. No  
> > comas cadaveres. No seas necr?fago.
> > 
> > * * *
> > 
> > SDL mailing list  
> > SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> > [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![icculus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/icculus/32/81_2.png) [@icculus](https://discourse.libsdl.org/u/icculus)\
**Post date:** [August 22, 2012, 4:23pm UTC](https://discourse.libsdl.org/t/important-sdl-bug-keyboard-and-mouse-classes-dont-work-please-help/19076/5 "2012-08-22T16:23:23Z")

</div>

> publicstaticvoidMain()  
> {  
> Video.Initialize();  
> Video.SetVideoMode(800, 600, 24);  
> for( ; ; )  
> {  
> Video.Screen.Fill(Color.Orange);  
> Video.Screen.Update();  
> if(Mouse.IsButtonPressed(MouseButton.PrimaryButton)

Having not used C#, I can’t say for certain, but if you had written this  
in C, you would need to tell SDL to run it’s event queue, otherwise it  
won’t ever notice mouse or keyboard input (and thus, always tell you  
that the mouse button isn’t pressed).

A quick Googling says there’s something like Event.Run() you should call  
somewhere. You’ll have to look into it further, but something like that  
should make IsButtonPressed() work correctly.

Example code: [http://swinbrain.ict.swin.edu.au/wiki/Sdl\_Dot\_Net\_Tutorial](http://swinbrain.ict.swin.edu.au/wiki/Sdl_Dot_Net_Tutorial)

–ryan.

---

<div class="post-metadata">

**Author:** ![Christian\_Leger](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/c/ecae2f/32.png) [@Christian\_Leger](https://discourse.libsdl.org/u/Christian_Leger)\
**Post date:** [August 22, 2012, 5:58pm UTC](https://discourse.libsdl.org/t/important-sdl-bug-keyboard-and-mouse-classes-dont-work-please-help/19076/6 "2012-08-22T17:58:31Z")

</div>

Hi,

Pablo you’re very welcome. I try to help anyone that I think I can  
help, and the same is true for many people here. Fabio makes a good  
point - it’s difficult sometimes to answer people who might be jumping  
to certain conclusions, like if there is a bug or not. How you choose  
your words can often make a difference, and I’d say it’s good to show  
you know the difference between what you know and what you don’t.  
Extra care has to be placed on what you _might think_ you know but  
actually don’t. I’m not the best at this which is why I always qualify  
my statements with ‘is it possible that’ and ‘am I wrong to suppose  
that…’. It’s my airbag for those times where I slip outside my  
universal politeness zone.

Take care to draw the line between what you really know (100% or 90%),  
and what you don’t really know. Everything you don’t 100% know is open  
to questioning. People here are very polite and they won’t question  
you as easily as you will, if you’re willing to do it. The more easily  
you show yourself questioning your own line of reasoning (which means,  
the more willing you are to investigate and demonstrate your  
investigations - in as much detail as required but as simple as  
possible, with all unnecessary detail left out) , the more people will  
jump on your investigation to help out. That’s my pop philosophy 🙂

TL; DR: what Fabio said 😃

What Ryan suggests is a better expression of what I was trying to say:  
in C, you have to poll the event queue to find out if anything was  
generated by the input (or other) subsystems. Your C# code doesn’t  
seem to have any calls directly related to polling, and that is why I  
pointed out that my ignorance of C# could be a blind spot. If I didn’t  
mention it, I should have mentioned event polling.

Please let us know if you are able to use something like Event.run.

If you are still having difficulties, I suggest you get your hands on  
a demo that uses SDL in C#, because I would be surprised if that  
doesn’t work out of the box. Then you can carefully compare your event  
processing code to the code in the demo, and I think there is a good  
chance you will make progress with that.

Good luck!

ChristianOn Wed, Aug 22, 2012 at 12:23 PM, Ryan C. Gordon wrote:

> > publicstaticvoidMain()  
> > {  
> > Video.Initialize();  
> > Video.SetVideoMode(800, 600, 24);  
> > for( ; ; )  
> > {  
> > Video.Screen.Fill(Color.Orange);  
> > Video.Screen.Update();  
> > if(Mouse.IsButtonPressed(MouseButton.PrimaryButton)
> 
> Having not used C#, I can’t say for certain, but if you had written this in  
> C, you would need to tell SDL to run it’s event queue, otherwise it won’t  
> ever notice mouse or keyboard input (and thus, always tell you that the  
> mouse button isn’t pressed).
> 
> A quick Googling says there’s something like Event.Run() you should call  
> somewhere. You’ll have to look into it further, but something like that  
> should make IsButtonPressed() work correctly.
> 
> Example code: [http://swinbrain.ict.swin.edu.au/wiki/Sdl\_Dot\_Net\_Tutorial](http://swinbrain.ict.swin.edu.au/wiki/Sdl_Dot_Net_Tutorial)
> 
> –ryan.
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Jared\_Maddox](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/8baadc/32.png) [@Jared\_Maddox](https://discourse.libsdl.org/u/Jared_Maddox)\
**Post date:** [August 23, 2012, 3:49am UTC](https://discourse.libsdl.org/t/important-sdl-bug-keyboard-and-mouse-classes-dont-work-please-help/19076/7 "2012-08-23T03:49:10Z")

</div>

> work : Please HELP!!!  
> Message-ID:  
> \<1345589937.35683.YahooMailNeo at [web124903.mail.ne1.yahoo.com](http://web124903.mail.ne1.yahoo.com)\>  
> Content-Type: text/plain; charset=“iso-8859-1”

> Can you confirm this and tell me how to solve it? It seems there are not too  
> many list members that use C# with SDL, but I supposse and hope that someone  
> is able to terminate with this problem … my Mario game really was getting  
> very nice  
> ?  
> Thank you very much  
> ?  
> Pablo

I was looking through the mailing-list archives recently, and it looks  
like you’ve been postoing on this game for a while. Always nice to see  
some activity, so thanks.\> Date: Tue, 21 Aug 2012 15:58:57 -0700 (PDT)

> From: Pablo Marty   
> To: “sdl at [lists.libsdl.org](http://lists.libsdl.org)”   
> Subject: [SDL] important SDL BUG : Keyboard and Mouse classes dont

> Date: Tue, 21 Aug 2012 23:17:21 -0700 (PDT)  
> From: Pablo Marty   
> To: Christian Leger \<chrism.leger at [gmail.com](http://gmail.com)\>, SDL Development List  
>   
> Subject: [SDL] someone who uses C# SDL please - Re: important SDL BUG  
> : Keyboard and Mouse classes dont work : Please HELP!!!  
> Message-ID:  
> \<1345616241.57956.YahooMailNeo at [web124904.mail.ne1.yahoo.com](http://web124904.mail.ne1.yahoo.com)\>  
> Content-Type: text/plain; charset=“iso-8859-1”

> I wonder, is C#SDL library (I mean the binarys, the DLLs) the same than the  
> C/C++ library, or the VB one, or others. I really doubt if this could be an  
> SDL bug. Perhaps the SDL library for C/C++ hasn t this problem, and the C#'s  
> one does …  
> ?

As a matter of fact, no, SDL# (or whatever it’s proper name is) isn’t  
actually part of the SDL project. That, I suspect, is why you’re  
finding little help (and finding problems). It’s certainly why I  
haven’ been posting on this, since I don’t even use C# (lately I’ve  
even been shifting to plain C!).

> Could someone who uses C# (and SdlDotNet or C#SDL) tell me what to do with  
> this? I would thank you very much

I’m afraid that for real help you’ll probably need to try the SDL#  
project’s own resources, though whether there’s any activity there I  
don’t know.

> Pablo

> Date: Wed, 22 Aug 2012 12:23:23 -0400  
> From: “Ryan C. Gordon”   
> To: SDL Development List   
> Subject: Re: [SDL] someone who uses C# SDL please - Re: important SDL  
> BUG : Keyboard and Mouse classes dont work : Please HELP!!!  
> Message-ID: \<5035077B.9040002 at [icculus.org](http://icculus.org)\>  
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed

> Having not used C#, I can’t say for certain, but if you had written this  
> in C, you would need to tell SDL to run it’s event queue, otherwise it  
> won’t ever notice mouse or keyboard input (and thus, always tell you  
> that the mouse button isn’t pressed).
> 
> A quick Googling says there’s something like Event.Run() you should call  
> somewhere. You’ll have to look into it further, but something like that  
> should make IsButtonPressed() work correctly.
> 
> Example code: [http://swinbrain.ict.swin.edu.au/wiki/Sdl\_Dot\_Net\_Tutorial](http://swinbrain.ict.swin.edu.au/wiki/Sdl_Dot_Net_Tutorial)
> 
> –ryan.

He’s specifically said that he’s avoiding using the Event class so  
that he can use multithreading, though some sort of marshalling system  
might work. Unfortunately, such a system would probably be somewhat  
redundant as well, since SDL# presumably has one of it’s own.

> Date: Wed, 22 Aug 2012 13:58:31 -0400  
> From: Christian Leger \<chrism.leger at [gmail.com](http://gmail.com)\>  
> To: SDL Development List   
> Subject: Re: [SDL] someone who uses C# SDL please - Re: important SDL  
> BUG : Keyboard and Mouse classes dont work : Please HELP!!!  
> Message-ID:  
> \<CAHgimD9=k+QpseCHr-OVVK1MiyD6v7fnNt\_2dhnNG3EVjz+gBA at [mail.gmail.com](http://mail.gmail.com)\>  
> Content-Type: text/plain; charset=ISO-8859-1
> 
> Hi,

> If you are still having difficulties, I suggest you get your hands on  
> a demo that uses SDL in C#, because I would be surprised if that  
> doesn’t work out of the box. Then you can carefully compare your event  
> processing code to the code in the demo, and I think there is a good  
> chance you will make progress with that.

I suspect that he already has. He’s been posting off-and-on about  
various problems that he’s needed help with, this is just the most  
recent one (and presumably an attempt to make the game faster). I  
strongly suspect that he’s simply outgrown the constraints of the demo  
code.

---

<div class="post-metadata">

**Author:** ![Pablo\_Marty](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Pablo\_Marty](https://discourse.libsdl.org/u/Pablo_Marty)\
**Post date:** [August 24, 2012, 2:02am UTC](https://discourse.libsdl.org/t/important-sdl-bug-keyboard-and-mouse-classes-dont-work-please-help/19076/8 "2012-08-24T02:02:56Z")

</div>

Thanks to you, Jared  
?  
I also found out, searching the Internet, that C# SDL (or [SDL.NET](http://SDL.NET)) is not supported at all !!! … and as one of you told me, the forum or chat of C# SDL Main page is not alive  
?  
Well, fortunately, I also know C (plain C, not C++) … I used the DJGPP(C/C++ for DOS) for a time, but it s no longer suported in any actual machine

Here you said you use C now, so, if I shift to C I won t have problems? What C Development Environment (or Compiler, or SDK) should I use? There is a Visual C/C++ for .NET? (because I m used to Visual Studio s nice Editor) … Where can I get SDL for C?  
Thank you

About my game, now I m writting a new version, … now it s much better, nothing to do with the first version  
I returned to using the Events class loop, and it worked again, but I still want to be able to use Threads and ignore that Events loop, … that is, to handle my own loops, like this

for ( ; ; )  
{  
??? ReadKbrd();  
??? DrawGame();  
}

Asesinar y comer un perro o un gato es lo mismo q hacerlo a una vaca, un pollo, un cerdo o un pez. El genocidio no discrimina. No seas complice de genocidas. No seas genocida. En la vida tarde o temprano todo vuelve. No comas cadaveres. No seas necr?[fago.De](http://fago.De): Jared Maddox   
Para: sdl at [lists.libsdl.org](http://lists.libsdl.org)  
Enviado: jueves, 23 de agosto de 2012 0:49  
Asunto: Re: [SDL] someone who uses C# SDL please - Re: important SDL BUG : Keyboard and Mouse classes dont work : Please HELP!!!

> Date: Tue, 21 Aug 2012 15:58:57 -0700 (PDT)  
> From: Pablo Marty \<@Pablo\_Marty\>  
> To: “sdl at [lists.libsdl.org](http://lists.libsdl.org)”   
> Subject: [SDL] important SDL BUG : Keyboard and Mouse classes dont  
> ??? work :??? Please HELP!!!  
> Message-ID:  
> ??? \<1345589937.35683.YahooMailNeo at [web124903.mail.ne1.yahoo.com](http://web124903.mail.ne1.yahoo.com)\>  
> Content-Type: text/plain; charset=“iso-8859-1”

> Can you confirm this and tell me how to solve it? It seems there are not too  
> many list members that use C# with SDL, but I supposse and hope that someone  
> is able to terminate with this problem … my Mario game really was getting  
> very nice  
> ?  
> Thank you very much  
> ?  
> Pablo

I was looking through the mailing-list archives recently, and it looks  
like you’ve been postoing on this game for a while. Always nice to see  
some activity, so thanks.

> Date: Tue, 21 Aug 2012 23:17:21 -0700 (PDT)  
> From: Pablo Marty \<@Pablo\_Marty\>  
> To: Christian Leger \<chrism.leger at [gmail.com](http://gmail.com)\>,??? SDL Development List  
> ???   
> Subject: [SDL] someone who uses C# SDL please - Re: important SDL BUG  
> ??? :??? Keyboard and Mouse classes dont work : Please HELP!!!  
> Message-ID:  
> ??? \<1345616241.57956.YahooMailNeo at [web124904.mail.ne1.yahoo.com](http://web124904.mail.ne1.yahoo.com)\>  
> Content-Type: text/plain; charset=“iso-8859-1”

> I wonder, is C#SDL library (I mean the binarys, the DLLs) the same than the  
> C/C++ library, or the VB one, or others. I really doubt if this could be an  
> SDL bug. Perhaps the SDL library for C/C++ hasn t this problem, and the C#'s  
> one does …  
> ?

As a matter of fact, no, SDL# (or whatever it’s proper name is) isn’t  
actually part of the SDL project. That, I suspect, is why you’re  
finding little help (and finding problems). It’s certainly why I  
haven’ been posting on this, since I don’t even use C# (lately I’ve  
even been shifting to plain C!).

> Could someone who uses C# (and SdlDotNet or C#SDL) tell me what to do with  
> this? I would thank you very much

I’m afraid that for real help you’ll probably need to try the SDL#  
project’s own resources, though whether there’s any activity there I  
don’t know.

> Pablo

> Date: Wed, 22 Aug 2012 12:23:23 -0400  
> From: “Ryan C. Gordon”   
> To: SDL Development List   
> Subject: Re: [SDL] someone who uses C# SDL please - Re: important SDL  
> ??? BUG : Keyboard and Mouse classes dont work : Please HELP!!!  
> Message-ID: \<5035077B.9040002 at [icculus.org](http://icculus.org)\>  
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed

> Having not used C#, I can’t say for certain, but if you had written this  
> in C, you would need to tell SDL to run it’s event queue, otherwise it  
> won’t ever notice mouse or keyboard input (and thus, always tell you  
> that the mouse button isn’t pressed).
> 
> A quick Googling says there’s something like Event.Run() you should call  
> somewhere. You’ll have to look into it further, but something like that  
> should make IsButtonPressed() work correctly.
> 
> Example code: [http://swinbrain.ict.swin.edu.au/wiki/Sdl\_Dot\_Net\_Tutorial](http://swinbrain.ict.swin.edu.au/wiki/Sdl_Dot_Net_Tutorial)
> 
> –ryan.

He’s specifically said that he’s avoiding using the Event class so  
that he can use multithreading, though some sort of marshalling system  
might work. Unfortunately, such a system would probably be somewhat  
redundant as well, since SDL# presumably has one of it’s own.

> Date: Wed, 22 Aug 2012 13:58:31 -0400  
> From: Christian Leger \<chrism.leger at [gmail.com](http://gmail.com)\>  
> To: SDL Development List   
> Subject: Re: [SDL] someone who uses C# SDL please - Re: important SDL  
> ??? BUG : Keyboard and Mouse classes dont work : Please HELP!!!  
> Message-ID:  
> ??? \<CAHgimD9=k+QpseCHr-OVVK1MiyD6v7fnNt\_2dhnNG3EVjz+gBA at [mail.gmail.com](http://mail.gmail.com)\>  
> Content-Type: text/plain; charset=ISO-8859-1
> 
> Hi,

> If you are still having difficulties, I suggest you get your hands on  
> a demo that uses SDL in C#, because I would be surprised if that  
> doesn’t work out of the box. Then you can carefully compare your event  
> processing code to the code in the demo, and I think there is a good  
> chance you will make progress with that.

I suspect that he already has. He’s been posting off-and-on about  
various problems that he’s needed help with, this is just the most  
recent one (and presumably an attempt to make the game faster). I  
strongly suspect that he’s simply outgrown the constraints of the demo  
code.

* * *

SDL mailing list  
SDL at [lists.libsdl.org](http://lists.libsdl.org)  
[http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Jared\_Maddox](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/8baadc/32.png) [@Jared\_Maddox](https://discourse.libsdl.org/u/Jared_Maddox)\
**Post date:** [August 24, 2012, 4:52am UTC](https://discourse.libsdl.org/t/important-sdl-bug-keyboard-and-mouse-classes-dont-work-please-help/19076/9 "2012-08-24T04:52:43Z")

</div>

> BUG : Keyboard and Mouse classes dont work : Please HELP!!!  
> Message-ID:  
> \<1345773776.32134.YahooMailNeo at [web124901.mail.ne1.yahoo.com](http://web124901.mail.ne1.yahoo.com)\>  
> Content-Type: text/plain; charset=“iso-8859-1”
> 
> Thanks to you, Jared  
> ?  
> I also found out, searching the Internet, that C# SDL (or [SDL.NET](http://SDL.NET)) is not  
> supported at all !!! … and as one of you told me, the forum or chat of C#  
> SDL Main page is not alive  
> ?  
> Well, fortunately, I also know C (plain C, not C++) … I used the  
> DJGPP(C/C++ for DOS) for a time, but it s no longer suported in any actual  
> machine
> 
> Here you said you use C now, so, if I shift to C I won t have problems? What  
> C Development Environment (or Compiler, or SDK) should I use? There is a  
> Visual C/C++ for .NET? (because I m used to Visual Studio s nice Editor) …

Well, I didn’t say that there won’t be problems, bugs even pop up in  
SDL 1.2 on occasion, but almost everything is already fixed.

As for the compiler suite you should use, I use MinGW/MSys, so you  
should really ask someone who uses a gui. 😉

However, there are several free open source IDEs, and Microsoft also  
provides one called MSVC++ (the C# version you’re used to started out  
with the C and C++ versions). However, .Net is not directly available  
through C or C++, you have to use Microsoft’s proprietary  
compatibility system for C++. If you really want .Net, then you might  
as well just use the compatibility system to provide your own SDL  
wrapper for C#.

Fortunately, the C version of SDL is fully compatible with C++, so if  
you don’t need stuff from .Net, then you can go that route (though I  
think MSVC++ is written in C#, so if that’s what you were talking  
about…).

> Where can I get SDL for C?  
> Thank you

The primary SDL site is here: [http://www.libsdl.org/](http://www.libsdl.org/) . If you look to  
the side, under “Downloads” it says “SDL 1.2” and “SDL HG”. The first  
is a link to a download page, the second is a link to a SCM page. The  
already released stuff is in the first link, the in-development stuff  
is in the second link.

> About my game, now I m writting a new version, … now it s much better,  
> nothing to do with the first version  
> I returned to using the Events class loop, and it worked again, but I still  
> want to be able to use Threads and ignore that Events loop, … that is, to  
> handle my own loops, like this
> 
> for ( ; ; )  
> {  
> ??? ReadKbrd();  
> ??? DrawGame();  
> }

I don’t know C#, but I assume that by this point they’ve provided a  
thread-safe queue container (first-in, first-out). If you have the  
event handlers just store event messages into that container then you  
should be able to pull them out in your own loop in another thread.

That having been said, I don’t know C#, or how SDL# implemented their  
wrapper, so this might not work. The only way to know is to  
investigate it.\> Date: Thu, 23 Aug 2012 19:02:56 -0700 (PDT)

> From: Pablo Marty   
> To: SDL Development List   
> Subject: Re: [SDL] someone who uses C# SDL please - Re: important SDL
