Page 1 of 2
ExamineKeayboard() and compiler...
Posted: Sun Aug 20, 2006 4:58 pm
by Skipsy
Hi folks,
I have a strange problem : When I run the debugger I get the message :
"OpenScreen() or OpenWindowedScreen must be called before use the keyboardcommands."
I have the same kind of message when I try the command 'ExamineMouse'.
I am using the command "OpenWindow()" and the program runs fine (the keyboard is manage), it only happened when debugging.
Any idea ????
Thks,
WW
Posted: Sun Aug 20, 2006 5:01 pm
by netmaestro
Those are screen commands. In PureBasic you can open a screen with OpenScreen, or a windowed screen with OpenWindowedScreen, or simpy open a window with OpenWindow. In the first two cases InitSprite() must be called first to initialize a directx7 environment, which is the environment required for the keyboard and mouse libraries. You don't need these at all for a standard GUI application, they're more suited to games.
Posted: Sun Aug 20, 2006 5:29 pm
by Skipsy
Well... It sounds "logic" but in this case I don't understand why the
keyboeards and mouse commands work perfectly... Until I use the debugger (?)
Still strange

Posted: Sun Aug 20, 2006 7:18 pm
by Derek
Can you post an example of the code you are using?
Posted: Sun Aug 20, 2006 10:54 pm
by Tranquil
Skipsy wrote:Well... It sounds "logic" but in this case I don't understand why the
keyboeards and mouse commands work perfectly... Until I use the debugger (?)
Still strange

I use ExamineKeyboards() without a screen too. for that reason I disabled the debugger at the keyboard commands.
It makes possible to catch keyboard events from all window application without the use of API which comes very handy and works fine on all tested plattforms.
Posted: Mon Aug 21, 2006 8:03 am
by Skipsy
Hi,
Here is a code that works fine but debugging is not possible :
Code: Select all
OpenWindow(1, 100, 100, 600, 600, "Test", #PB_Window_SystemMenu|#PB_Window_TitleBar)
If InitMouse() = 0 Or InitKeyboard() = 0
MessageRequester("Erreur", "Prob DirectX", 0)
End
EndIf
Repeat
ExamineKeyboard()
Until KeyboardReleased(#PB_Key_Escape)
beep_ (1000,50)
CloseWindow (1)
End
WW
Posted: Mon Aug 21, 2006 8:20 am
by netmaestro
Well if it's safe, why would the debugger be set up to prevent it

Posted: Mon Aug 21, 2006 8:29 am
by Dare
Good question.
However, unless there is a very good reason to not go with this, I think I will use it.
Edit:
If there are no serious downsides, this should remain as it is a good feature.
Posted: Mon Aug 21, 2006 10:21 am
by Derek
If I run your program with debugger on then it stops at the examinekeyboard command with the error like you say, if I run without the debugger on then the program freezes and has to be stopped by windows.
I guess something isn't working right and thats why the debugger won't let it run.
I'm using XP home with sp2 on an amd64 3000+
Posted: Mon Aug 21, 2006 10:25 am
by Derek
Scrap that, it was just me not pressing escape and seeing the hourglass and not being able to move the window I assumed the program had crashed.
Should have some kind of event system in there in case windows get confused over too many events.
Posted: Mon Aug 21, 2006 10:27 am
by Skipsy
Safe ?
Well, this is just a short part of code. The goal was to show that
ExamineKeyboard() works fine WITHOUT OpenScreen() or OpenWindowedScreen. But the debugger "crashes". This means that
it is not possible to use the debugger.

Posted: Mon Aug 21, 2006 10:30 am
by Derek
Perhaps the debugger is just hardwired to expect an openscreen or openwindowedscreen before allowing examinekeyboard.
Not really a bug but an oversight.
Posted: Mon Aug 21, 2006 10:35 am
by Derek
Just wondering, why do you want to read the keys using the keyboard library when you are using windows and not screens.
Cant you just read the keys using an api call or is it that you need cross platform compatibility?
Does the debugger still stop working if you run this program on a mac I wonder?
Posted: Mon Aug 21, 2006 10:42 am
by Dare
Seems like Tranquil has a reasonable work-around for the debugger in his post above?
Edit: For eg, stick some macros/procedures into the code and replace all keyboardCommand type statements with myKeyboardCommands (or whatever)
Code: Select all
Macro myExamineKeyboard()
DisableDebugger
ExamineKeyboard()
EnableDebugger
EndMacro
Procedure myKeyboardReleased(ky)
DisableDebugger
r=KeyboardReleased(ky)
EnableDebugger
ProcedureReturn r
EndProcedure
OpenWindow(1, 100, 100, 600, 600, "Test", #PB_Window_SystemMenu|#PB_Window_TitleBar)
If InitMouse() = 0 Or InitKeyboard() = 0
MessageRequester("Erreur", "Prob DirectX", 0)
End
EndIf
Repeat
myExamineKeyboard()
Until myKeyboardReleased(#PB_Key_Escape)
Beep_ (1000,50)
CloseWindow (1)
End
Posted: Mon Aug 21, 2006 12:10 pm
by Skipsy
I am using the keyboard to stop the program at a specific point... (I know I
can also use the degugger for this).
I was just wondering why the debugger doesn't like this command with
OpenWindow().
Iam going to use GetAsyncKeyState_() and GetKeyState_().
Thks for your replies.
WW