Page 1 of 1

Best way to shortcut enter in string gadgets?

Posted: Sat Sep 06, 2003 12:27 am
by Karbon
Since I need the enter key to function normally in editor gadgets and stuff I cannot use AddKeyboardShortcut()

Is this the best way to handle detecting enter being pressed in a string gadget?

Code: Select all

          
        Select MyEventID
          
          Case #WM_KEYDOWN
            
            If EventwParam() = 13
            
              Select EventGadgetID()
              
                Case #String_Gadget_Here
                
                  Debug "Return key pressed in string gadget"
                  
              EndSelect

            EndIf

         EndSelect

Posted: Sat Sep 06, 2003 1:11 am
by aszid
you could always add a keyboard shortcut for enter, and have it insert a CR+LF at the current cursor position... just a thought, haven't tried it out though...

Re: Best way to shortcut enter in string gadgets?

Posted: Sat Sep 06, 2003 3:38 am
by PB
I'd probably just do this in your main loop (when a gadget event occurs):

Code: Select all

If GetAsyncKeyState_(#VK_RETURN)<>0 And GetFocus_()=GadgetID(#gadnum)
  ; Do whatever...
EndIf
It waits until Return (aka Enter) is pressed and checks if the desired gadget
has the focus at the same time.

Posted: Sat Sep 06, 2003 4:04 am
by Karbon
Hey PB, thanks for the reply..

How else would I check for enter being pressed other than the way I'm doing it now and the example you posted?

Posted: Sat Sep 06, 2003 7:58 am
by PB
> How else would I check for enter being pressed other than the way I'm
> doing it now and the example you posted?

Using keyboard shortcuts in addition to the GetFocus() API, like so:

Code: Select all

If OpenWindow(1,300,250,400,200,#PB_Window_SystemMenu,"Window")
  CreateGadgetList(WindowID())
  ButtonGadget(1,20,50,80,25,"Press ALT+&1") : AddKeyboardShortcut(1,#PB_Shortcut_Alt|#PB_Shortcut_1,1)
  StringGadget(2,120,50,100,25,"Press Enter here") : AddKeyboardShortcut(1,#PB_Shortcut_Return,2)
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_Event_Menu
      which=EventMenuID()
      If which=1
        Debug "ALT+1 was pressed"
      Else
        If GetFocus_()=GadgetID(2) ; If you remove this then pressing Enter works anywhere.
          Debug "Enter was pressed"
        EndIf
      EndIf
    EndIf
  Until ev=#PB_EventCloseWindow
EndIf

Posted: Sat Sep 06, 2003 9:23 pm
by Karbon
Gotcha. Thanks PB!!