Joined: 8/24/2011(UTC) Posts: 34 Location: New Zealand
Thanks: 4 times
|
Commands are generally the way to go, but I also need access to the key ups and downs as they happen; pretty much the same as the equivalent Windows events, but we can abstract things and just work with InputButton keys after the various implementations do a translation. So for example, I added the following delegates to WindowsKeyboard: Code:
public delegate void KeyDelegate(InputButton key);
public static KeyDelegate OnKeyDown;
public static KeyDelegate OnKeyUp;
You could use events but I think a single delegate should be sufficient. Then I wired them up to the WindowsKeyboard.Update implementation: Code:
foreach (InputButton newKey in keysDown)
{
// ...
if (OnKeyDown != null)
{
OnKeyDown(newKey);
}
}
// ...
foreach (InputButton keyNotPressedAnymore in keysUp)
{
// ...
if (OnKeyUp != null)
{
OnKeyUp(keyNotPressedAnymore);
}
}
This seems to work well for my project, but ideally KeyDelegate, OnKeyDown and OnKeyUp are pushed into the BaseKeyboard class. Then each derived Keyboard implementation just needs to make sure it fires the delegates accordingly. What do you think?
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.