Keyboard Input and Surface Manipulation

Hi Guys,

First off, I love this library! Really it's great stuff. I do have a couple questions though.

Using AgateLib.InputLib's keyboard event the left and right shift and controls are not being differentiated.

  1.         void Keyboard_KeyDown(InputEventArgs e)
  2.         {
  3.             if (e.KeyCode == KeyCode.ShiftRight)
  4.                  ...

The debugger reads the e.KeyCode as just "Shift" and not "ShiftRight" (or ShiftLeft for that matter). This is a feature I need. Is there anything I can do to fix this?

Also, I'm not sure if this is me not being able to find it, or if it's simply not implemented, is there a way to flip a surface? I could always just create a flipped version of every image need, but if there was a built in way to do it that would be great!

Thanks,
Jon Leah

Jon, You can flip a sprite

Jon,

You can flip a sprite horizontally or vertically by using a negative value with ScaleWidth or ScaleHeight, respectively.

Tom

Thanks Tom, The surfaces are

Thanks Tom,

The surfaces are drawing flipped!

A little thing I did notice to keep in mind is that if ScaleWidth is -1, the DisplayWidth becomes negative as well. I'm not certain that should be the case. It works, but it feels a bit odd.

Jon

The leftshift/rightshift

The leftshift/rightshift issue is a limitation of Windows Forms. I think there is a way around it but I will have to do a little research.

Hey Kanato, I was thinking

Hey Kanato,

I was thinking that it's pretty important for a gaming library to be able to differentiate left and right keys, so I did a little research on my own.

Anyways, I implemented it in your code. It's a pretty big hack because you're right, .net doesn't support left and right keys, but here is the hacked/rewritten OnKeyDown method. Also, this should only work in a win32 environment. :(

Hopefully you can take it somewhere, but this does "work". I also added AltLeft and AltRight to your enumeration.

-Jon Leah

  1.         using System.Runtime.InteropServices;
  2.         ...
  3.         //Jon Leah
  4.         [DllImport("User32.dll", CharSet = CharSet.Auto)]
  5.         public static extern ushort GetKeyState(int virtKey);
  6.  
  7.         private static void OnKeyDown(KeyCode id, KeyModifiers mods, int repeatCount)
  8.         {
  9.  
  10.             ushort state;
  11.  
  12.             state = GetKeyState(0xA0);
  13.             if (state > 1)
  14.                 id = KeyCode.ShiftLeft;
  15.             state = GetKeyState(0xA1);
  16.             if (state > 1)
  17.                 id = KeyCode.ShiftRight;
  18.  
  19.             state = GetKeyState(0xA2);
  20.             if (state > 1)
  21.                 id = KeyCode.ControlLeft;
  22.             state = GetKeyState(0xA3);
  23.             if (state > 1)
  24.                 id = KeyCode.ControlRight;
  25.  
  26.             state = GetKeyState(0xA4);
  27.             if (state > 1)
  28.                 id = KeyCode.AltLeft;
  29.             state = GetKeyState(0xA5);
  30.             if (state > 1)
  31.                 id = KeyCode.AltRight;
  32.  
  33.             if (KeyDown != null)
  34.                 KeyDown(new InputEventArgs(id, mods, repeatCount));
  35.         }

Yeah, this is pretty

Yeah, this is pretty important. I remember struggling with this a while back, which is why the ShiftLeft and ShiftRight enumerations were already there, but I eventually moved on with the intention of revisiting it later. I will try to look into this over the weekend and see if I can't find a more cross-platform solution.