It is currently Mon Apr 06, 2020 4:49 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Window event carriage return
PostPosted: Wed Feb 12, 2020 2:44 am 
Offline
User
User

Joined: Tue Feb 11, 2020 7:50 am
Posts: 10
Hi, how do I enable a form to capture the carriage return when pressed.

So I have form with username and password for login purposes.

When the user presses carriage return, I want it to be like the 'login' button which I capture and process.

I looked at all the form events, and I didn't find it.

Can someone please advice.


Top
 Profile  
Reply with quote  
 Post subject: Re: Window event carriage return
PostPosted: Wed Feb 12, 2020 3:29 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 2305
Location: Singapore
lesserpanda wrote:
...When the user presses carriage return, I want it to be like the 'login' button which I capture and process...

One approach:
Code:
Procedure doLogin()
  MessageRequester("Login", "Login button clicked!")
  ; login processes here...
EndProcedure

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
If OpenWindow(0, 0, 0, 300, 130, "Keyboard Shortcuts", wFlags)
  StringGadget (1, 10, 10, 280, 30, "Name")
  StringGadget (2, 10, 50, 280, 30, "Password") 
  ButtonGadget (3, 10, 90, 280, 30, "LOGIN") 
  SetActiveGadget(1)
 
  AddKeyboardShortcut(0, #PB_Shortcut_Return, 1) 
 
  Repeat
    event = WaitWindowEvent()
    Select event
       
      Case #PB_Event_CloseWindow
        appQuit = #True
       
      Case #PB_Event_Gadget
        Select EventGadget()
           
          Case 3 ;login button
            doLogin()             
           
        EndSelect
       
      Case #PB_Event_Menu
        Select EventMenu()           
           
          Case 1 ;return key
            Select GetActiveGadget()
               
              Case 1 ;name box
                SetActiveGadget(2)
               
              Case 2 ;password box
                doLogin()                 
               
            EndSelect           
           
        EndSelect
       
    EndSelect
   
  Until appQuit
 
EndIf
When the keyboard focus is on the NAME input, carriage return will set the focus to the PASSWORD input. When the keyboard focus is on the PASSWORD input, carriage return will simulate the LOGIN button being clicked.

_________________
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!


Top
 Profile  
Reply with quote  
 Post subject: Re: Window event carriage return
PostPosted: Wed Feb 12, 2020 5:11 am 
Offline
User
User

Joined: Tue Feb 11, 2020 7:50 am
Posts: 10
Hi thanks for the quick reply and great code. Much appreciated.

It's all good now and can capture the chr(13) but how do I get the values of those StringGadgets? Sorry for the newbie question. First day on PB.

I was trying ..

Code:
If OpenWindow(0, x, y, width, height, "Login", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_WindowCentered)
    strEmail = StringGadget(1, 430, 130, 220, 25, "", #PB_String_LowerCase)
    TextGadget(#PB_Any, 350, 130, 70, 25, "Email:")
    ButtonGadget(#PB_Any, 520, 210, 130, 45, "Login")
    TextGadget(#PB_Any, 350, 170, 70, 25, "Password")
    strPassword = StringGadget(2, 430, 170, 220, 25, "", #PB_String_Password)
    AddKeyboardShortcut(0, #PB_Shortcut_Return, 1)
    Repeat
      event = WaitWindowEvent()
      Select event
         
        Case #PB_Event_CloseWindow
          appQuit = #True
         
        Case #PB_Event_Gadget
          Select EventGadget()
             
            Case 3 ;login button
              email.s = GetGadgetText(strEmail)
              password.s = GetGadgetText(strPassword)
              doLogin(email, password)       
             
          EndSelect
         
        Case #PB_Event_Menu
          Select EventMenu()           
             
            Case 1 ;return key
              Select GetActiveGadget()
                 
                Case 1 ;name box
                  SetActiveGadget(2)
                 
                Case 2 ;password box               
                  email.s = GetGadgetText(strEmail)
                  password.s = GetGadgetText(strPassword)
                  doLogin(email, password)       
                 
              EndSelect           
             
          EndSelect
         
      EndSelect
     
    Until appQuit
  EndIf


But it says specified #Gadget is not intialized


Top
 Profile  
Reply with quote  
 Post subject: Re: Window event carriage return
PostPosted: Wed Feb 12, 2020 5:39 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 2305
Location: Singapore
lesserpanda wrote:
...how do I get the values of those StringGadgets?

Simply like this:
Code:
Procedure doLogin()
  msgText$  = "Name: " + GetGadgetText(1) + #CRLF$ +
              "Password: " + GetGadgetText(2)
  MessageRequester("Login", msgText$)
EndProcedure

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
If OpenWindow(0, 0, 0, 300, 130, "Keyboard Shortcuts", wFlags)
  StringGadget (1, 10, 10, 280, 30, "Name")
  StringGadget (2, 10, 50, 280, 30, "Password") 
  ButtonGadget (3, 10, 90, 280, 30, "LOGIN") 
  SetActiveGadget(1)
 
  AddKeyboardShortcut(0, #PB_Shortcut_Return, 1) 
 
  Repeat
    event = WaitWindowEvent()
    Select event
       
      Case #PB_Event_CloseWindow
        appQuit = #True
       
      Case #PB_Event_Gadget
        Select EventGadget()
           
          Case 3 ;login button
            doLogin()             
           
        EndSelect
       
      Case #PB_Event_Menu
        Select EventMenu()           
           
          Case 1 ;return key
            Select GetActiveGadget()
               
              Case 1 ;name box
                SetActiveGadget(2)
               
              Case 2 ;password box
                doLogin()                 
               
            EndSelect           
           
        EndSelect
       
    EndSelect
   
  Until appQuit
 
EndIf


One point to note: the following syntax assigns the number 2 as the gadget number (result is non-zero if the gadget is instantiated successfully):
Code:
result = StringGadget(2, 430, 170, 220, 25, "", #PB_String_Password)

The syntax for assigning the gadget number dynamically to the strPassword variable is:
Code:
strPassword = StringGadget(#PB_Any, 430, 170, 220, 25, "", #PB_String_Password)

That is the cause of the specified #Gadget is not intialized error.

_________________
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!


Top
 Profile  
Reply with quote  
 Post subject: Re: Window event carriage return
PostPosted: Wed Feb 12, 2020 9:12 am 
Offline
User
User

Joined: Tue Feb 11, 2020 7:50 am
Posts: 10
Got it.. Thank you very much!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye