Seite 1 von 1

problem mit eventmenu und keyboardshortcut.

Verfasst: 06.06.2015 16:36
von True29
hallo , folgender code für login, funktioniert mit dem button gut , jedoch nicht mit der enter / return taste.
normal sollte er bei einer eingabe es nicht von selbst nochmal probieren.

hier zum vergleich im beispiel code , login klicken .. 1x login a , bei enter kommt mind 3x login b. was nicht passieren sollte .
es soll hier auch nur ein event geben , sozusagen muss das event irgendwie neu gesetzt werden.
geht um die stelle bei EventMenu() = 15 .

danke für die hilfe.

Code: Alles auswählen

EnableExplicit

Enumeration
  #LOGINWINDOW
  #Button_login
  #Button_reg
  #Button_cancel
  #Button_forgott
  #NICK
  #PW
  #Text_Login_State
EndEnumeration

  Global Text_login_titel.s="log in"
  Global Text_login_button_login.s="log in"
  Global Text_login_button_reg.s="register"
  Global Text_login_button_cancel.s="cancel"
  Global Text_login_button_forgott.s="new password"
  Global Text_login_lable_nick.s= "nickname"
  Global Text_login_lable_pw.s= "password"
  Global Text_login_help_nick.s= "enter your nickname"
  Global Text_login_help_pw.s= "enter your password"   
  Global Text_login_state.s= "Status:"
  Global login_Status.s,loginversuche,OpenLoginwindow
  Global LoginState.i,login.s
  
Procedure OpenLoginwindow()  
  OpenWindow(#LOGINWINDOW, 0, 0, 240, 160, Text_login_titel, #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
  ButtonGadget(#Button_login, 130, 100, 100, 20, Text_login_button_login)
  ButtonGadget(#Button_reg, 10, 130, 100, 20, Text_login_button_reg)
  ButtonGadget(#Button_cancel, 130, 130, 100, 20, Text_login_button_cancel)
  ButtonGadget(#Button_forgott,10,100, 100, 20,Text_login_button_forgott)
  
  StringGadget(#NICK, 10, 30, 100, 25, "Test")
  GadgetToolTip(#NICK,Text_login_help_nick)
  
  StringGadget(#PW, 130, 30, 100, 25, "Test",#PB_String_Password)
  GadgetToolTip(#PW, Text_login_help_pw)  
  
  TextGadget(#PB_Any, 10, 10, 60, 17, Text_login_lable_nick)
  TextGadget(#PB_Any, 130, 10, 60, 20,Text_login_lable_pw)
  
  TextGadget(#PB_Any, 10, 70, 60, 20,Text_login_state)
  TextGadget(#Text_Login_State, 60, 70, 200, 20,login_Status)
  
  HideWindow(#LOGINWINDOW,#False)
EndProcedure

Procedure Login()      
  Protected Nick.s = GetGadgetText(#NICK)
  Protected PW.s = GetGadgetText(#PW) 
  
  If GetGadgetText(#NICK) = "Demo" Or GetGadgetText(#NICK) = "demo" : ProcedureReturn 2 : EndIf  
  ;// zuviele loginversuche ?  
  If loginversuche >= 3
    SetGadgetText(#Text_Login_State,"max log in trys reach")    
    ProcedureReturn #False
  EndIf
  SetGadgetText(#Text_Login_State,"try to log in")
  If Not ((Nick = "" Or PW = "" )) 
    If ((Len(Nick.s) >= 5) And (Len(Nick.s) < 20) And (Len(PW.s) >= 5) And (Len(PW.s) < 20))      
      SetGadgetText(#Text_Login_State,"log in")
        SetGadgetText(#Text_Login_State,"log in ok")
        ProcedureReturn #False
    Else
      SetGadgetText(#Text_Login_State,"information wrong")
      ProcedureReturn #False
    EndIf
  Else
    SetGadgetText(#Text_Login_State,"missing fields")
    ProcedureReturn #False
  EndIf
EndProcedure  

Define Event
OpenLoginwindow = #True

  Repeat  
    If OpenLoginwindow = #True
      OpenLoginwindow()
      AddKeyboardShortcut(#LOGINWINDOW,#PB_Shortcut_Return,15)  
      AddKeyboardShortcut(#LOGINWINDOW,#PB_Shortcut_Escape,16)  
      OpenLoginwindow = #False
    EndIf  
    
    
    Event = WaitWindowEvent()     
    If Event = #PB_Event_Gadget
      Select EventGadget()        
        Case #Button_login
          Debug "login a"
          LoginState = login()          
        Case #Button_reg
          ;// call website registration
          ;RunProgram(#Webadress_registergame)
        Case #Button_cancel
          End        
        Case #Button_forgott
          ;RunProgram(#Webadress_forgottpw)
          ;// call website forgott pb
      EndSelect
      ;// close window
    ElseIf Event = #PB_Event_CloseWindow
      CloseWindow(GetActiveWindow())
      End
    ElseIf EventMenu() = 15  
      Debug "login b"
      LoginState = login()      
      Debug LoginState
    ElseIf EventMenu() = 16      
      CloseWindow(GetActiveWindow())
      End
    EndIf
    
    ;// loginstate 2 = demo
    If LoginState = 2
      Break    
    EndIf  
  Until LoginState = #True And login = "ok"  
  CloseWindow(GetActiveWindow())  

__________________________________________________
Thread verschoben
Allgemein>Anfänger
06.06.2015
RSBasic

Re: problem mit eventmenu und keyboardshortcut.

Verfasst: 06.06.2015 16:46
von RSBasic
Deine If-Abfrage ist falsch. Du kannst nicht WaitWindowEvent() und gleichzeitig EventMenu() abfragen. Die Beiden haben miteinander nichts zu tun und müssen separat verglichen werden. In dem Fall muss EventMenu() nur dann abgefragt werden, wenn auch ein Menü-Event (#PB_Event_Menu) ausgelöst wurde.
Richtig wäre:

Code: Alles auswählen

  ElseIf Event = #PB_Event_Menu
    If EventMenu() = 15
      ;...
    ElseIf EventMenu() = 16
      ;...
    EndIf
  EndIf
Also:

Code: Alles auswählen

EnableExplicit

Enumeration
  #LOGINWINDOW
  #Button_login
  #Button_reg
  #Button_cancel
  #Button_forgott
  #NICK
  #PW
  #Text_Login_State
EndEnumeration

Global Text_login_titel.s="log in"
Global Text_login_button_login.s="log in"
Global Text_login_button_reg.s="register"
Global Text_login_button_cancel.s="cancel"
Global Text_login_button_forgott.s="new password"
Global Text_login_lable_nick.s= "nickname"
Global Text_login_lable_pw.s= "password"
Global Text_login_help_nick.s= "enter your nickname"
Global Text_login_help_pw.s= "enter your password"   
Global Text_login_state.s= "Status:"
Global login_Status.s,loginversuche,OpenLoginwindow
Global LoginState.i,login.s

Procedure OpenLoginwindow() 
  OpenWindow(#LOGINWINDOW, 0, 0, 240, 160, Text_login_titel, #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
  ButtonGadget(#Button_login, 130, 100, 100, 20, Text_login_button_login)
  ButtonGadget(#Button_reg, 10, 130, 100, 20, Text_login_button_reg)
  ButtonGadget(#Button_cancel, 130, 130, 100, 20, Text_login_button_cancel)
  ButtonGadget(#Button_forgott,10,100, 100, 20,Text_login_button_forgott)
  
  StringGadget(#NICK, 10, 30, 100, 25, "Test")
  GadgetToolTip(#NICK,Text_login_help_nick)
  
  StringGadget(#PW, 130, 30, 100, 25, "Test",#PB_String_Password)
  GadgetToolTip(#PW, Text_login_help_pw) 
  
  TextGadget(#PB_Any, 10, 10, 60, 17, Text_login_lable_nick)
  TextGadget(#PB_Any, 130, 10, 60, 20,Text_login_lable_pw)
  
  TextGadget(#PB_Any, 10, 70, 60, 20,Text_login_state)
  TextGadget(#Text_Login_State, 60, 70, 200, 20,login_Status)
  
  HideWindow(#LOGINWINDOW,#False)
EndProcedure

Procedure Login()     
  Protected Nick.s = GetGadgetText(#NICK)
  Protected PW.s = GetGadgetText(#PW)
  
  If GetGadgetText(#NICK) = "Demo" Or GetGadgetText(#NICK) = "demo" : ProcedureReturn 2 : EndIf 
  ;// zuviele loginversuche ? 
  If loginversuche >= 3
    SetGadgetText(#Text_Login_State,"max log in trys reach")   
    ProcedureReturn #False
  EndIf
  SetGadgetText(#Text_Login_State,"try to log in")
  If Not ((Nick = "" Or PW = "" ))
    If ((Len(Nick.s) >= 5) And (Len(Nick.s) < 20) And (Len(PW.s) >= 5) And (Len(PW.s) < 20))     
      SetGadgetText(#Text_Login_State,"log in")
      SetGadgetText(#Text_Login_State,"log in ok")
      ProcedureReturn #False
    Else
      SetGadgetText(#Text_Login_State,"information wrong")
      ProcedureReturn #False
    EndIf
  Else
    SetGadgetText(#Text_Login_State,"missing fields")
    ProcedureReturn #False
  EndIf
EndProcedure 

Define Event
OpenLoginwindow = #True

Repeat 
  If OpenLoginwindow = #True
    OpenLoginwindow()
    AddKeyboardShortcut(#LOGINWINDOW,#PB_Shortcut_Return,15) 
    AddKeyboardShortcut(#LOGINWINDOW,#PB_Shortcut_Escape,16) 
    OpenLoginwindow = #False
  EndIf 
  
  
  Event = WaitWindowEvent()     
  If Event = #PB_Event_Gadget
    Select EventGadget()       
      Case #Button_login
        Debug "login a"
        LoginState = login()         
      Case #Button_reg
        ;// call website registration
        ;RunProgram(#Webadress_registergame)
      Case #Button_cancel
        End       
      Case #Button_forgott
        ;RunProgram(#Webadress_forgottpw)
        ;// call website forgott pb
    EndSelect
    ;// close window
  ElseIf Event = #PB_Event_CloseWindow
    CloseWindow(GetActiveWindow())
    End
  ElseIf Event = #PB_Event_Menu
    If EventMenu() = 15 
      Debug "login b"
      LoginState = login()     
      Debug LoginState
    ElseIf EventMenu() = 16     
      CloseWindow(GetActiveWindow())
      End
    EndIf
  EndIf
  ;// loginstate 2 = demo
  If LoginState = 2
    Break   
  EndIf 
Until LoginState = #True And login = "ok" 
CloseWindow(GetActiveWindow())  
Am besten ist auch noch, wenn du EventMenu() nur einmal aufrust. Den zurückgegebenen Wert kannst du in eine Variable speichern.

Re: problem mit eventmenu und keyboardshortcut.

Verfasst: 06.06.2015 17:29
von True29
super das wars , danke ;)