Xna Keyboard Error
Xna Keyboard Error
Xna Keyboard Error
Xna Keyboard Error
Xna Keyboard Error
Xna Keyboard Error Xna Keyboard Error Xna Keyboard Error Xna Keyboard Error Xna Keyboard Error Xna Keyboard Error Xna Keyboard Error Xna Keyboard Error
Xna Keyboard Error Xna Keyboard Error
Xna Keyboard Error
Go Back  Xtreme Visual Basic Talk > > > Xna Keyboard Error


Reply
 
Thread Tools Display Modes
  #1  
Old 11-30-2013, 08:01 AM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default 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
HResult=-2146233079
Message=An invalid operation occurred when trying to query the keyboard state. The result code was 0.
Source=Microsoft.Xna.Framework
StackTrace:
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
InnerException:

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

Game1.vb

Code:
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
66
67        keyState = Keyboard.GetState() ' <-- Error here
68
69        If (Keyboard.GetState().IsKeyDown(Keys.Up)) = True Then MsgBox("Up key was pressed")
70
71        ' TODO: Add your update logic here
72        MyBase.Update(gameTime)
73
74    End Sub
The second error occurs in the Program.vb class but
this one is understandable since there was already a
previous error.

Program.vb

Code:
1   #If WINDOWS Or XBOX Then
2
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
13
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.
Reply With Quote
  #2  
Old 11-30-2013, 10:43 AM
snarfblam's Avatar
snarfblamXna Keyboard Error snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 896
Default

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.
http://stackoverflow.com/questions/1...keyboard-state
__________________
C# _VB.NET _
Reply With Quote
  #3  
Old 11-30-2013, 02:21 PM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default

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
window.

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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Xna Keyboard Error
Xna Keyboard Error
Xna Keyboard Error Xna Keyboard Error
Xna Keyboard Error
Xna Keyboard Error
Xna Keyboard Error Xna Keyboard Error Xna Keyboard Error Xna Keyboard Error Xna Keyboard Error Xna Keyboard Error Xna Keyboard Error
Xna Keyboard Error
Xna Keyboard Error
 
Xna Keyboard Error
Xna Keyboard Error
 
-->