InitKeyboard problem

Just starting out? Need help? Post your questions and find answers here.
larry
New User
New User
Posts: 9
Joined: Fri Sep 02, 2005 7:31 pm

InitKeyboard problem

Post by larry »

Sample code:

result = InitKeyboard()
a$ = Str(result)
MessageRequester("Result of InitKeyboard", a$, 0)
ExamineKeyboard()

Rresult of InitKeyboard() is 1 (good), ExamineKeyboard() (or any other keyboard command) produces: "[ERROR] InitKeyboard() must be called before use the keyboard commands."

Running Fedora 4 and most current PureBasic. Any help would be most appreciated.
8)
Jellybean
User
User
Posts: 95
Joined: Wed Aug 24, 2005 7:33 pm

Post by Jellybean »

You should report in the bugs forum that the error message is wrong. The real error message should be: "OpenScreen() or OpenWindowedScreen() must be called before use of the keyboard commands."
larry
New User
New User
Posts: 9
Joined: Fri Sep 02, 2005 7:31 pm

Post by larry »

Jellybean, I tried that but it did not solve problem, thank you for your help.

The code I gave is a concise sample from PB programs in the example folder (ie: keyboard.pb). They should all work but fail because of this error.
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Re: InitKeyboard problem

Post by va!n »

larry wrote:Rresult of InitKeyboard() is 1 (good), ExamineKeyboard() (or any other keyboard command) produces: "[ERROR] InitKeyboard() must be called before use the keyboard commands."
is that the source, producing the error on your machine? works fine here wihtout any trouble... what up with following example?

Code: Select all

result = InitKeyboard()
MessageRequester("Result of InitKeyboard", Str(result), 0)

Repeat
 ExamineKeyboard() 
Until KeyboardPushed(#PB_Key_Q)

MessageRequester("You pressed Q","Quit program", 0)
End
Whats OS version and ServicePacks are you using?
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: InitKeyboard problem

Post by traumatic »

va!n wrote:is that the source, producing the error on your machine? works fine here wihtout any trouble... what up with following example?
Come on, the provided source can't work for you as a screen (resp. windowed
screen) has to be initialised prior to ExamineKeyboard().
va!n wrote:Whats OS version and ServicePacks are you using?
FC4 :)

larry:
Sorry, I can't test on linux but you're saying the original example source
that comes with PB doesn't work either? I'm curious because the code you
posted just can't work as it is (Jellybean already stated that) and some-
times one tends to simply oversee certain things. Well, ok, at least I tend to... ;)
Good programmers don't comment their code. It was hard to write, should be hard to read.
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

in purebasic 3.30 u can use keyboard commands without open screen on windows at least...............
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
larry
New User
New User
Posts: 9
Joined: Fri Sep 02, 2005 7:31 pm

Post by larry »

Everyone, thanks for the help so far. I should have been clearer in my original post, the code sample is just an excerpt showing the heart of the problem. The full code is shown below. It fails with the error I have been talking about, InitKeyboard() has been executed successfully. This program is a working example provided by PB. Any ideas?

If InitKeyboard() = 0
MessageRequester("Error", "Can't open DirectX 7", 0)
End
EndIf

If InitSprite() = 0
MessageRequester("Error", "Can't open DirectX 7", 0)
End
EndIf

MessageRequester("Information", "This will test the fast keyboard access..."+Chr(10)+"Press 'ESC' to quit!", 0)

If OpenScreen(640, 480, 16, "Sprite")

x = 100
y = 100

If LoadSprite(0, "data/Player_1.bmp", 0) = 0
CloseScreen()
MessageRequester("PureBasic", "Can't load the sprite file (data/Player_1.bmp)", 0)
End
EndIf

Repeat

FlipBuffers()
ClearScreen(0,0,0)

ExamineKeyboard()

If KeyboardPushed(#PB_Key_Left)
x-1
EndIf

If KeyboardPushed(#PB_Key_Right)
x+1
EndIf

If KeyboardPushed(#PB_Key_Up)
y-1
EndIf

If KeyboardPushed(#PB_Key_Down)
y+1
EndIf

DisplaySprite(0, x, y)

Until KeyboardPushed(#PB_Key_Escape)

Else
MessageRequester("Error", "Impossible to open a 680*480 16 bit screen",0)
EndIf

End
8)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I can reproduce your error. I do it by executing the examinekeyboard() command before opening the screen. If I do it after the screen is open, everything works fine.

You provide a couple of code snippets. One is a brief snippet that I can't tell is located before or after openscreen(). The other is a snippet from the examples folder written correctly, and again I don't know where you are altering it to get the error.

But - I'm pretty sure just placing the examinekeyboard() command after openscreen() will solve your problem.

InitKeyboard() does not require an open screen, and that may be causing you some confusion. All that does is make sure dx7 is available and prepare the keyboard commands. That can take place anywhere in your code at all. Just don't execute examinekeyboard() without an open screen.
BERESHEIT
larry
New User
New User
Posts: 9
Joined: Fri Sep 02, 2005 7:31 pm

Post by larry »

Thanks Netmaestro, but does not solve problem. The second code sample, correctly written, will not work. openscreen() is called before examinekeyboard(), and error still happens. Does keyboard commands not work under Linux :?:
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

The keyboard commandset is documented as being applicable to all OS's, but not having a linux box I'm unable to help you investigate further. Something seems amiss, though. Good luck with it.
BERESHEIT
Post Reply