ExamineKeayboard() and compiler...

Just starting out? Need help? Post your questions and find answers here.
Skipsy
User
User
Posts: 98
Joined: Wed Apr 30, 2003 12:26 pm
Location: France

ExamineKeayboard() and compiler...

Post 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
Beware of the man who has the solution before he understands the problem...
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
Skipsy
User
User
Posts: 98
Joined: Wed Apr 30, 2003 12:26 pm
Location: France

Post 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 :shock:
Beware of the man who has the solution before he understands the problem...
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Can you post an example of the code you are using?
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post 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 :shock:
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.
Tranquil
Skipsy
User
User
Posts: 98
Joined: Wed Apr 30, 2003 12:26 pm
Location: France

Post 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
Beware of the man who has the solution before he understands the problem...
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Well if it's safe, why would the debugger be set up to prevent it :?:
BERESHEIT
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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.
Dare2 cut down to size
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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+
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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.
Skipsy
User
User
Posts: 98
Joined: Wed Apr 30, 2003 12:26 pm
Location: France

Post 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.
:(
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Perhaps the debugger is just hardwired to expect an openscreen or openwindowedscreen before allowing examinekeyboard.

Not really a bug but an oversight.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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?
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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
Dare2 cut down to size
Skipsy
User
User
Posts: 98
Joined: Wed Apr 30, 2003 12:26 pm
Location: France

Post 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
Beware of the man who has the solution before he understands the problem...
Post Reply