Page 1 of 1

ExamineKeyboard() with Debugger = on?

Posted: Mon Nov 13, 2017 3:35 pm
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?

Re: ExamineKeyboard() with Debugger = on?

Posted: Mon Nov 13, 2017 5:41 pm
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()

Re: ExamineKeyboard() with Debugger = on?

Posted: Mon Nov 13, 2017 8:13 pm
by oO0XX0Oo
That works fine, thank you mk-soft!