Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Game Programming (http://www.xtremevbtalk.com/-net-game-programming/)
-   -   Xna Keyboard Error (http://www.xtremevbtalk.com/-net-game-programming/326632-xna-keyboard-error.html)

VB_Alien 11-30-2013 08:01 AM

Xna Keyboard Error
I don't know if this site is really geared towards
the xna framework but i thought that i would ask
anyway. It doesn't hurt to ask, as they always say.

Anyway. I'm using VB Net 2010 pro, along with xna 4.0
and windows phone 7.1.

My trouble is that when i create a new xna game project
and insert the code to detect the keyboard key presses,
i get an error, right from the start up of the application.

Here is the full exception error that i get.

System.InvalidOperationException was unhandled
Message=An invalid operation occurred when trying to query the keyboard state. The result code was 0.
at Microsoft.Xna.Framework.Input.Keyboard.GetState(PlayerIndex playerIndex)
at WindowsGame2.Game1.Update(GameTime gameTime) in C:\Users\xxxxxxxxxxx\Desktop\WindowsGame2\WindowsGame2\WindowsGame2\Ga me1.vb:line 67
at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
at Microsoft.Xna.Framework.Game.Run()
at WindowsGame2.Program.Main(String[] args) in C:\Users\xxxxxxxxx\Desktop\WindowsGame2\WindowsGame2\WindowsGame2\Prog ram.vb:line 9

The first error starts in the game1 class and here it is
with line numbers added.



56    ''' <summary>
57    ''' Allows the game to run logic such as updating the world,
58    ''' checking for collisions, gathering input, and playing audio.
59    ''' </summary>
60    ''' <param name="gameTime">Provides a snapshot of timing values.</param>
61    Protected Overrides Sub Update(ByVal gameTime As GameTime)
62        ' Allows the game to exit
63        If GamePad.GetState(PlayerIndex.One).Buttons.Back = ButtonState.Pressed Then
64            Me.Exit()
65        End If
67        keyState = Keyboard.GetState() ' <-- Error here
69        If (Keyboard.GetState().IsKeyDown(Keys.Up)) = True Then MsgBox("Up key was pressed")
71        ' TODO: Add your update logic here
72        MyBase.Update(gameTime)
74    End Sub

The second error occurs in the Program.vb class but
this one is understandable since there was already a
previous error.



3  Module Program
4      ''' <summary>
5      ''' The main entry point for the application.
6      ''' </summary>
7        Sub Main(ByVal args As String())
8          Using game As New Game1()
9              game.Run()  '<--- Error here
10          End Using
11      End Sub
12    End Module
14  #End If

This seems to be a regular problem with xna using both
C# and or VB Net but i have yet, been able to find a
solution that will fix the error.

I was hoping someone here may have had this problem
and found a solution to fix it.

snarfblam 11-30-2013 10:43 AM

I've never run into this problem, but I googled it and found a couple other people with the same issue. This is the only instance I ran into where someone was able to shed any light on it.

VB_Alien 11-30-2013 02:21 PM

That site said that their problem was with commodo
anti-virus firewall, of which i do have.

I completely shut that software down and i turned off
windows firewall as well, but still had the same results.

I'm clueless to as to what the problem could be. Lots of
people using both C# and VB Net are reporting the same
problem and there isn't any mention of a fix for this yet.

Now that MS has officially quit supporting xna, i'm going to
assume that they will never resolve this issue.

I have this issue when i create a new windows game project
and try to add support code for keyboard presses.

Somewhere online, i found code that basically creates the
xna game class by first opening a new windows forms application.

Then you just add a new class and name it Game1 and add the
supplied code to it. It's the same code already in an xna game
class. Then you add a module to your project and insert code that
tells the project to run. Then you delete the windows form and what
is left is an xna game class that does create and run a xna game

I added keyboard support code in the class and the keyboard works
great, so i stumped as to why that same code won't work with a
real xna game project.

All times are GMT -6. The time now is 08:08 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.