Best way to shortcut enter in string gadgets?

Just starting out? Need help? Post your questions and find answers here.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Best way to shortcut enter in string gadgets?

Post 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
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
User avatar
aszid
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 01, 2003 8:38 pm
Location: California, USA
Contact:

Post 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...
--Aszid--

Making crazy people sane, starting tomorrow.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Best way to shortcut enter in string gadgets?

Post 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.
Last edited by PB on Sat Sep 06, 2003 7:57 am, edited 1 time in total.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post 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?
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Gotcha. Thanks PB!!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Post Reply