Lost My #PB_EventType_LostFocus -- Bug?? [SOLVED]

Just starting out? Need help? Post your questions and find answers here.
Randy Walker
Addict
Addict
Posts: 991
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Lost My #PB_EventType_LostFocus -- Bug?? [SOLVED]

Post by Randy Walker »

Great one for netmaestro since this comes from his code sample. This first sample is slighly modified version of his sample and it works fine. Run it in the debugger and watch what happens when click the debugger window to force the sample window to lose focus:

Code: Select all

#KB_Return = #PB_Shortcut_Return + 49152

Procedure KeyboardGyration()
  Select EventType()
    Case #PB_EventType_Focus
      Debug "focus on window "
      AddKeyboardShortcut(0, #PB_Shortcut_Return, #KB_Return)
    Case #PB_EventType_LostFocus
      Debug "lost focus on window "
      RemoveKeyboardShortcut(0, #PB_Shortcut_Return)
  EndSelect
EndProcedure

OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)

TextGadget(#PB_Any, 10,20,100,16,"Enter Something:")
StringGadget(0, 110,20,300,20,"")
EditorGadget(1,10,50,400,400)
SetActiveGadget(0)

Repeat
  EventID = WaitWindowEvent() 
  
  Select EventID
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          EventTyp.l = EventType()
          KeyboardGyration()
      EndSelect
    Case #PB_Event_Menu
      Select EventMenu()
        Case #KB_Return
          SetActiveGadget(1)
      EndSelect
  EndSelect
  
Until EventID = #PB_Event_CloseWindow
You saw it post ''lost focus on window'' to the debug window, right? (will assume you did)

Now, I took this code sample *only* one step further. Its broken and *logically* speaking, I see nothing wrong with what I did, but grant you I am a dummy so please explain why what I did is wrong, or confirm this is a bug. I *believe* now this is the origin of all my problems upgrading from v4.20 to 4.60

Run it in the debugger as before and watch what happens when click the debugger window to force the sample window to lose focus. You will NOT see it post ''lost focus on window'':

Code: Select all

Global EventTyp.l
#KB_Return = #PB_Shortcut_Return + 49152

Procedure KeyboardGyration()
  Select EventTyp.l
    Case #PB_EventType_Focus
      Debug "focus on window "
      AddKeyboardShortcut(0, #PB_Shortcut_Return, #KB_Return)
    Case #PB_EventType_LostFocus
      Debug "lost focus on window "
      RemoveKeyboardShortcut(0, #PB_Shortcut_Return)
  EndSelect
EndProcedure

OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)

TextGadget(#PB_Any, 10,20,100,16,"Enter Something:")
StringGadget(0, 110,20,300,20,"")
EditorGadget(1,10,50,400,400)
SetActiveGadget(0)

Repeat
  EventID = WaitWindowEvent() 
  liveWin = GetActiveWindow() ; subroutines listedd here in the main loop. 
  EventTyp.l = EventType()
  Select liveWin 
    Case 0
      
      Select EventID
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 0
              EventTyp.l = EventType()
              KeyboardGyration()
          EndSelect
        Case #PB_Event_Menu
          Select EventMenu()
            Case #KB_Return
              SetActiveGadget(1)
          EndSelect
      EndSelect
      
  EndSelect
Until EventID = #PB_Event_CloseWindow
Last edited by Randy Walker on Thu Feb 09, 2012 4:47 am, edited 3 times in total.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 991
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Lost My #PB_EventType_LostFocus -- Bug??

Post by Randy Walker »

Sorry... I had to edit the 2nd sample so there are no stupid ommisions as in the original post.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Lost My #PB_EventType_LostFocus -- Bug??

Post by RASHAD »

I do not know what you are after but...

Code: Select all

Global EventTyp.l
#KB_Return = #PB_Shortcut_Return + 49152

Procedure KeyboardGyration()
  Select EventType()
    Case #PB_EventType_Focus
      Debug "focus on window "
      AddKeyboardShortcut(0, #PB_Shortcut_Return, #KB_Return)
    Case #PB_EventType_LostFocus
      Debug "lost focus on window "
      RemoveKeyboardShortcut(0, #PB_Shortcut_Return)
  EndSelect
EndProcedure

OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)

TextGadget(#PB_Any, 10,20,100,16,"Enter Something:")
StringGadget(0, 110,20,300,20,"")
EditorGadget(1,10,50,400,400)
SetActiveGadget(0)

Repeat
  EventID = WaitWindowEvent() 
  liveWin = GetActiveWindow() ; subroutines listedd here in the main loop.
  Select liveWin 
    Case 0,-1
      Select EventID
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 0
              EventTyp.l = EventType()
              KeyboardGyration()
          EndSelect
        Case #PB_Event_Menu
          Select EventMenu()
            Case #KB_Return
              SetActiveGadget(1)
          EndSelect
      EndSelect
      
  EndSelect
Until EventID = #PB_Event_CloseWindow
Egypt my love
Randy Walker
Addict
Addict
Posts: 991
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Lost My #PB_EventType_LostFocus -- Bug??

Post by Randy Walker »

RASHAD wrote:I do not know what you are after but...
Huh... Thanks Rashad. You fixed it. I didn't realize GetActiveWindow() was returning -1 on external windows.

Now that I see what you did I cleaned it up a bit more. Basicly I want to be able to manage multiple windows 0,1,2,3... from my main loop. Later I will post a more suitable sample. For now, this is how I applied your fix:

Code: Select all

Global EventTyp.l
#KB_Return = #PB_Shortcut_Return + 49152

Procedure KeyboardGyration()
  Select EventTyp.l
    Case #PB_EventType_Focus
      Debug "focus on window "
      AddKeyboardShortcut(0, #PB_Shortcut_Return, #KB_Return)
    Case #PB_EventType_LostFocus
      Debug "lost focus on window "
      RemoveKeyboardShortcut(0, #PB_Shortcut_Return)
  EndSelect
EndProcedure

OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)

TextGadget(#PB_Any, 10,20,100,16,"Enter Something:")
StringGadget(0, 110,20,300,20,"")
EditorGadget(1,10,50,400,400)
SetActiveGadget(0)

Repeat
  EventID = WaitWindowEvent()
  liveWin = GetActiveWindow() ; subroutines listedd here in the main loop.
  EventTyp.l = EventType()

  Select liveWin
    Case -1 ; external window took focus
      Select EventID
        Case #PB_Event_Gadget
          KeyboardGyration()
      EndSelect

    Case 0
      Select EventID
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 0
              KeyboardGyration()
          EndSelect
        Case #PB_Event_Menu
          Select EventMenu()
            Case #KB_Return
              SetActiveGadget(1)
          EndSelect
      EndSelect
      
  EndSelect
Until EventID = #PB_Event_CloseWindow
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Lost My #PB_EventType_LostFocus -- Bug??

Post by Demivec »

Randy Walker wrote:Now, I took this code sample *only* one step further. Its broken and *logically* speaking, I see nothing wrong with what I did, but grant you I am a dummy so please explain why what I did is wrong, or confirm this is a bug. I *believe* now this is the origin of all my problems upgrading from v4.20 to 4.60
You did not take it one *complete* step forward. The first example by netmaestro dealt with one window. Your example introduced the possibility of dealing with more than one window but didn't deal with more than one window. Your example therefore did not make a complete step forward. I have added the necessary code to complete the step. The code needs to deal with losing focus from the selected gadgets in any PB window.

In this new sample I have added an additional window (with a similar gadget setup) and added the ability to deal with more than one window by removing and adding the shortcut to the appropriate window when needed to deal with the StringGadget that is active there. You will have to move one of the created windows to see them both because they are placed on top of each other.

Code: Select all

Global EventTyp.l, liveWin, lastLiveWin
#KB_Return = #PB_Shortcut_Return + 49152

Procedure KeyboardGyration()
  Select EventType()
    Case #PB_EventType_Focus
      Debug "focus on window " + Str(liveWin)
      AddKeyboardShortcut(liveWin, #PB_Shortcut_Return, #KB_Return)
      lastLiveWin = liveWin
    Case #PB_EventType_LostFocus
      Debug "lost focus on window " + Str(lastLiveWin)
      RemoveKeyboardShortcut(lastLiveWin, #PB_Shortcut_Return)
  EndSelect
EndProcedure

OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)

TextGadget(#PB_Any, 10,20,100,16,"Enter Something:")
StringGadget(0, 110,20,300,20,"")
EditorGadget(1,10,50,400,400)
SetActiveGadget(0)

OpenWindow(2,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
TextGadget(#PB_Any, 10,20,100,16,"Enter Something:")
StringGadget(2, 110,20,300,20,"")
EditorGadget(3,10,50,400,400)
SetActiveGadget(2)

Repeat
  EventID = WaitWindowEvent() 
  liveWin = GetActiveWindow()
  Select EventID
    Case #PB_Event_Gadget ;only one gadget list for all windows
      EventTyp.l = EventType()
      Select EventGadget()
        Case 0, 2
          KeyboardGyration()
      EndSelect
    Case #PB_Event_Menu 
      Select EventMenu()
        Case #KB_Return
          Select liveWin ;menu events can take place on different windows
            Case 0
              SetActiveGadget(1)
            Case 1
              SetActiveGadget(3)
          EndSelect 
      EndSelect
  EndSelect
Until EventID = #PB_Event_CloseWindow
Randy Walker
Addict
Addict
Posts: 991
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Lost My #PB_EventType_LostFocus -- Bug??

Post by Randy Walker »

Demivec wrote:You did not take it one *complete* step forward. The first example by netmaestro dealt with one window. Your example introduced the possibility of dealing with more than one window but didn't deal with more than one window. Your example therefore did not make a complete step forward. I have added the necessary code to complete the step.
Ooops. Appearently you didn't. Seems this AddKeyboardShortcut workaround keeps requiring more and more workaround addendums every time we try to do something TOTALLY unrelated to the simple concern: "did someone press the enter key". :? And people keep trying to tell me this AddKeyboardShortcut is NOT a workaround :shock:
I'm beginning to see thats a true statement. It is NOT a workaround. It is a conglomeration of workarounds, because we are not done yet. All I did is add one simple button. Too much to ask for this notaworkaround...

Do this.
  • Run the code below using the debugger.
    Click on any external application to remove all focus from the demo program.
    Click directly on the [Hide Window] button.
    Watch the demo crash:

Code: Select all

Global EventTyp.l, liveWin, lastLiveWin
#KB_Return = #PB_Shortcut_Return + 49152

Procedure KeyboardGyration()
  Select EventType()
    Case #PB_EventType_Focus
      Debug "focus on window " + Str(liveWin)
      AddKeyboardShortcut(liveWin, #PB_Shortcut_Return, #KB_Return)
      lastLiveWin = liveWin
    Case #PB_EventType_LostFocus
      Debug "lost focus on window " + Str(lastLiveWin)
      RemoveKeyboardShortcut(lastLiveWin, #PB_Shortcut_Return)
  EndSelect
EndProcedure

OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)

TextGadget(#PB_Any, 10,20,100,16,"Enter Something:")
StringGadget(0, 110,20,300,20,"")
EditorGadget(1,10,50,400,400)
SetActiveGadget(0)

OpenWindow(2,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
TextGadget(#PB_Any, 10,20,100,16,"Enter Something:")
StringGadget(2, 110,20,300,20,"")
EditorGadget(3,10,50,400,400)
ButtonGadget(4,500,50,120,24,"Hide Window")
SetActiveGadget(2)

Repeat
  EventID = WaitWindowEvent()
  liveWin = GetActiveWindow()
  Select EventID
    Case #PB_Event_Gadget ;only one gadget list for all windows
      EventTyp.l = EventType()
      Select EventGadget()
        Case 0, 2
          KeyboardGyration()
        Case 4
          SetActiveGadget(2)
          HideWindow(2,1)
      EndSelect
    Case #PB_Event_Menu
      Select EventMenu()
        Case #KB_Return
          Select liveWin ;menu events can take place on different windows
            Case 0
              SetActiveGadget(1)
              HideWindow(2,0)
            Case 1
              SetActiveGadget(3)
          EndSelect
      EndSelect
  EndSelect
Until EventID = #PB_Event_CloseWindow
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Lost My #PB_EventType_LostFocus -- Bug?? [UNSOLVED]

Post by RASHAD »

Code: Select all

Global EventTyp.l, liveWin, lastLiveWin
#KB_Return = #PB_Shortcut_Return + 49152

Procedure KeyboardGyration()
  Select EventType()
    Case #PB_EventType_Focus
      Debug "focus on window " + Str(liveWin)
      If IsWindow(liveWin)
      AddKeyboardShortcut(liveWin, #PB_Shortcut_Return, #KB_Return)
      EndIf
      lastLiveWin = liveWin
    Case #PB_EventType_LostFocus
      Debug "lost focus on window " + Str(lastLiveWin)
      If IsWindow(lastLiveWin)
      RemoveKeyboardShortcut(lastLiveWin, #PB_Shortcut_Return)
      EndIf
  EndSelect
EndProcedure

OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)

TextGadget(#PB_Any, 10,20,100,16,"Enter Something:")
StringGadget(0, 110,20,300,20,"")
EditorGadget(1,10,50,400,400)
SetActiveGadget(0)

OpenWindow(2,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
TextGadget(#PB_Any, 10,20,100,16,"Enter Something:")
StringGadget(2, 110,20,300,20,"")
EditorGadget(3,10,50,400,400)
ButtonGadget(4,500,50,120,24,"Hide Window")
SetActiveGadget(2)

Repeat
  EventID = WaitWindowEvent()
  liveWin = GetActiveWindow()
  Select EventID
    Case #PB_Event_Gadget ;only one gadget list for all windows
      EventTyp.l = EventType()
      Select EventGadget()
        Case 0, 2
          KeyboardGyration()
        Case 4
          SetActiveGadget(2)
          HideWindow(2,1)
      EndSelect
    Case #PB_Event_Menu
      Select EventMenu()
        Case #KB_Return
          Select liveWin ;menu events can take place on different windows
            Case 0
              SetActiveGadget(1)
              HideWindow(2,0)
            Case 1
              SetActiveGadget(3)
          EndSelect
      EndSelect
  EndSelect
Until EventID = #PB_Event_CloseWindow

Egypt my love
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Lost My #PB_EventType_LostFocus -- Bug??

Post by Demivec »

Randy Walker wrote:
Demivec wrote:You did not take it one *complete* step forward. The first example by netmaestro dealt with one window. Your example introduced the possibility of dealing with more than one window but didn't deal with more than one window. Your example therefore did not make a complete step forward. I have added the necessary code to complete the step.
Ooops. Appearently you didn't. Seems this AddKeyboardShortcut workaround keeps requiring more and more workaround addendums every time we try to do something TOTALLY unrelated to the simple concern: "did someone press the enter key". :? And people keep trying to tell me this AddKeyboardShortcut is NOT a workaround :shock:
I'm beginning to see thats a true statement. It is NOT a workaround. It is a conglomeration of workarounds, because we are not done yet. All I did is add one simple button. Too much to ask for this notaworkaround...
Your welcome.

Concerning the 'workaround' term. I bet you are glad you didn't pursue a job as a maintenance mechanic. You would have referred to yourself and all of your tools (i.e. a screwdriver) in your toolbox as workarounds. After-all if something was working why would it need to be fixed?

You seem to be great at debugging but not so great at fixing. This means you keep taking only half a step forward.


RASHAD: thanks for the adding the test for a non-PB window. My original solution somehow missed it in my testing. :wink:
Randy Walker
Addict
Addict
Posts: 991
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Lost My #PB_EventType_LostFocus -- Bug??

Post by Randy Walker »

Demivec wrote:Your welcome.
You're quite right. That was rude of me. Not that I don't appreciate the help. Addmittedly I have a pea brain and its all a good deal more difficult for me than most people think. They don't see the time I struggle to disect, reassemble, look for lost pieces, re-reassemble again 2 or 3 times before I commit to anything... and still all too often come up short. Just this paragraph for example. Lost count. Anyway. Sorry i got too caught up in this battle with the code and failed to acknowledge the gift. Thank you for your help and I do mean that sincerely.
You seem to be great at debugging but not so great at fixing.
Actually I run the helpdesk and crew for a software company. My job is debugging. If the settings can't fix it then I turn the probem over to the programmers to fix the bug. I'm not a programmer. Never claimed to be and shun the comment when I here it. Don't feel I have earned that title and don't feel I ever will. Yes I wrote 24000+ lines of code to create a custom helpdesk solution for our company. All out of necessity -- not because I know what I am doing as I expect ''a programmer'' should.
Last edited by Randy Walker on Thu Feb 09, 2012 4:41 am, edited 1 time in total.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 991
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Lost My #PB_EventType_LostFocus -- Bug?? [UNSOLVED]

Post by Randy Walker »

RASHAD wrote:Thu Feb 09, 2012 07:05
I think Rashad has me figured out. Doesn't give me ammunition for a debate ... just the code solutions :lol:

Thank you Rashad!!! :!: :D
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Post Reply