[SOLVED] Catch Enter key without breaking it?

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

[SOLVED] Catch Enter key without breaking it?

Post by Randy Walker »

My old nemisis has returned and i can't figure it out. I need to know when Enter key is pressed inside an editorgadget without breaking the normal behavior. This will catch the enter key but does not move cursor to next line at the same time:

Code: Select all

If OpenWindow(1, 100,100,310,510, "My_QUICK_NOTE w/autosave", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_TitleBar)
  EditorGadget(1, 5, 5, 270, 500) : AddKeyboardShortcut(1,#PB_Shortcut_Return,2)
  Repeat
    _mess=WaitWindowEvent()
    If _mess=#PB_Event_Menu
      which=EventMenu()
      If which=2
        Debug "Enter was pressed"
      EndIf
    EndIf
  Until _mess=#PB_Event_CloseWindow 
EndIf
I'm hoping for solution that does not require a callback. I hate callbacks.
Last edited by Randy Walker on Tue Mar 04, 2025 9:07 pm, edited 1 time in total.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Catch Enter key without breaking it?

Post by RASHAD »

Hi Randy

Code: Select all

If OpenWindow(1, 100,100,310,510, "My_QUICK_NOTE w/autosave", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_TitleBar)
  EditorGadget(1, 5, 5, 270, 500) 
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit = 1
        
      Case #WM_CHAR
        key = EventwParam()
        If key = 13
          Debug "Return key pressed"
        EndIf
    EndSelect
  Until Quit = 1
EndIf
Egypt my love
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Catch Enter key without breaking it?

Post by Randy Walker »

RASHAD wrote: Tue Mar 04, 2025 12:37 am Hi Randy

Code: Select all

    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit = 1
        
      Case #WM_CHAR
        key = EventwParam()
        If key = 13
          Debug "Return key pressed"
        EndIf
    EndSelect
Wow!!1 Thanks RASHAD!!!! So PERFECT. Never would hve guessed to try WM_CHAR
You saved my life again. THANKS!!!!
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Catch Enter key without breaking it?

Post by Randy Walker »

UHHg ???? Appears there was a reply here from ChrisR according to Notifications but it mysteriously vanished.
Thanks anyway ChrisR :)
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
ChrisR
Addict
Addict
Posts: 1484
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Catch Enter key without breaking it?

Post by ChrisR »

yes, I hadn't refreshed, didn't see that Rahab had given the right answer :)
User avatar
blueb
Addict
Addict
Posts: 1118
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Catch Enter key without breaking it?

Post by blueb »

I love the smell of Rahab in the morning! :mrgreen:
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
ChrisR
Addict
Addict
Posts: 1484
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Catch Enter key without breaking it?

Post by ChrisR »

:lol:
Oops, sorry my friend Rashad, I guess it's my phone's automatic correction :oops:
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Catch Enter key without breaking it?

Post by Randy Walker »

blueb wrote: Tue Mar 04, 2025 1:13 pm I love the smell of Rahab in the morning! :mrgreen:
:shock: :shock:
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Catch Enter key without breaking it?

Post by Randy Walker »

ChrisR wrote: Tue Mar 04, 2025 3:00 pm :lol:
I guess it's my phone's automatic correction :oops:
I hate that so much. People that created and enabled that should be hung on he street corner for inflicting mass embarrassment. It's just not right. :twisted:
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Post Reply