Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Enselic

Probs with GetAsyncKeyState in C#

This topic is 5169 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have problems with this simple inputclass. Since .NET doesnt have a GetAsyncKeyState() counterpart, I use the Win32 variant. My "inputclass" looks like this:
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]

Share this post


Link to post
Share on other sites
Advertisement
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!