using System;
using System.Runtime.InteropServices;
namespace Enselic
{
// A basic class that handles input by using the old Win32-function GetAsyncKeyState()
public class WinInput
{
public static bool IsKeyDown( Keys k )
{
return (GetAsyncKeyState( (int)k ) & 8000) != 0;
}
// These values are the VK_-constants
public enum Keys
{
Left = 37,
Up = 38,
Right = 39,
Down = 40
}
// Imported Win32-func
[DllImport("User32.dll")]
private static extern short GetAsyncKeyState( int keyCode );
}
}
I can't get it to work properly so I wonder if any of you find any flaws in the code?
Here's what MSDN says about GetAsyncKeyState()
[edited by - Enselic on March 28, 2004 10:13:43 AM]
Probs with GetAsyncKeyState in C#
I have problems with this simple inputclass. Since .NET doesnt have a GetAsyncKeyState() counterpart, I use the Win32 variant. My "inputclass" looks like this:
quote:Original post by Enselic
I can''t get it to work properly
EEEP!
Try again, and include some more detail.
--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]
I can't get the IsKeyDown( Keys k )-method of the class to return true when it should. And it should return true when I call WinInput.IsKeyDown( WinInput.Keys.Up ) and the Up-key is down.
[edited by - Enselic on March 28, 2004 11:45:35 AM]
[edited by - Enselic on March 28, 2004 11:45:35 AM]
Shouldn''t that "& 8000" be "& 0x8000"? ie, its 8000 hex, not decimal. Apart from that it all looks cool.
Alan
Alan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement