ExamineKeyboard() with Debugger = on?

Windows specific forum
oO0XX0Oo
User
User
Posts: 78
Joined: Thu Aug 10, 2017 7:35 am

ExamineKeyboard() with Debugger = on?

Post by oO0XX0Oo »

Hi,

I'm trying to getting used to handle multiple windows with a single event loop
and I want to be able to close each of these windows with the ESC key, so
the code looks like this:

Code: Select all

EnableExplicit

; Create a constant for each window
Enumeration
  #MainWindow
  #OtherWindow
EndEnumeration

; Declare procedures
Declare MainWindowEvents(event)
Declare OtherWindowEvents(event)


; *************************************************************************************************

Procedure MainWindowEvents(event)
  ; Exit on ESC press
  If KeyboardReleased(#PB_Key_Escape)
    ProcedureReturn 1
  EndIf

  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn 1
  EndSelect
EndProcedure


Procedure OtherWindowEvents(event)
  ; Close on ESC press
  If KeyboardReleased(#PB_Key_Escape)
    CloseWindow(#OtherWindow)
  EndIf

  Select event
    Case #PB_Event_CloseWindow
      CloseWindow(#OtherWindow)
  EndSelect
EndProcedure


; *************************************************************************************************

Procedure Main()
  Protected event, exit

  ; We need this for ExamineKeyboard() / KeyboardReleased()
  InitKeyboard()

  OpenWindow(#MainWindow, 10, 10, 100, 100, "Title 1")
  OpenWindow(#OtherWindow, 110, 110, 100, 100, "Title 2")

  Repeat
    event = WaitWindowEvent()
    ExamineKeyboard()

    ; Check events for each window separately!
    Select EventWindow()
      Case #MainWindow
        exit = MainWindowEvents(event)
      Case #OtherWindow
        OtherWindowEvents(event)
    EndSelect
  Until exit
EndProcedure


; *************************************************************************************************

; Call the main procedure
Main()

The problem is, as long as the Debugger is on, running the code from the IDE
leads to a non-responding second window and the app crashes when I hit
the close button of it...

When the debugger is not active, the two windows behave just fine.

Do I use ExamineKeyboard() in a wrong way?
User avatar
mk-soft
Always Here
Always Here
Posts: 5337
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: ExamineKeyboard() with Debugger = on?

Post by mk-soft »

ExamineKeyboard ist eher was für OpenScreen(...). siehe Beispiel (PB)

Dafür gibt es eher 'AddKeyboardShortcut' die dann eine Menu-Event auslösen.

Ups... English
ExamineKeyboard is rather something for OpenScreen (...). see example (PB)
But there is rather' AddKeyboardShortcut' which will trigger a menu event.

Code: Select all

EnableExplicit

; Create a constant for each window
Enumeration
  #MainWindow
  #OtherWindow
EndEnumeration

; Declare procedures
Declare MainWindowEvents(event)
Declare OtherWindowEvents(event)


; *************************************************************************************************

Procedure MainWindowEvents(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn 1
    Case #PB_Event_Menu
      If EventMenu() = 1000
        ProcedureReturn 1
      EndIf
  EndSelect
EndProcedure


Procedure OtherWindowEvents(event)
  Select event
    Case #PB_Event_CloseWindow
      CloseWindow(#OtherWindow)
    Case #PB_Event_Menu
      If EventMenu() = 1000
        CloseWindow(#OtherWindow)
      EndIf
  EndSelect
EndProcedure


; *************************************************************************************************

Procedure Main()
  Protected event, exit

  OpenWindow(#MainWindow, 10, 10, 160, 100, "Title 1")
  OpenWindow(#OtherWindow, 110, 110, 160, 100, "Title 2")
  
  AddKeyboardShortcut(#MainWindow, #PB_Shortcut_Escape, 1000)
  AddKeyboardShortcut(#OtherWindow, #PB_Shortcut_Escape, 1000)
  
  Repeat
    event = WaitWindowEvent()
    
    ; Check events for each window separately!
    Select EventWindow()
      Case #MainWindow
        exit = MainWindowEvents(event)
      Case #OtherWindow
        OtherWindowEvents(event)
    EndSelect
  Until exit
EndProcedure


; *************************************************************************************************

; Call the main procedure
Main()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
oO0XX0Oo
User
User
Posts: 78
Joined: Thu Aug 10, 2017 7:35 am

Re: ExamineKeyboard() with Debugger = on?

Post by oO0XX0Oo »

That works fine, thank you mk-soft!
Post Reply