Page 1 of 1

InitKeyboard problem

Posted: Fri Sep 02, 2005 7:53 pm
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)

Posted: Fri Sep 02, 2005 8:45 pm
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."

Posted: Fri Sep 02, 2005 9:44 pm
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.

Re: InitKeyboard problem

Posted: Sat Sep 03, 2005 12:56 am
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?

Re: InitKeyboard problem

Posted: Sat Sep 03, 2005 1:09 am
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... ;)

Posted: Sat Sep 03, 2005 2:21 am
by lexvictory
in purebasic 3.30 u can use keyboard commands without open screen on windows at least...............

Posted: Sat Sep 03, 2005 4:37 pm
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)

Posted: Sat Sep 03, 2005 5:49 pm
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.

Posted: Sat Sep 03, 2005 7:05 pm
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 :?:

Posted: Sat Sep 03, 2005 7:56 pm
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.