Preventing use of tab key in EditorGadget

Just starting out? Need help? Post your questions and find answers here.
johnnyutah
User
User
Posts: 27
Joined: Sat Oct 16, 2004 1:25 pm

Preventing use of tab key in EditorGadget

Post by johnnyutah »

Hi,

Just a quick question. When someone presses the tab key I want to activate the next gadget and prevent the creation of a paragraph indent in the previous editor gadget.

I can activate the next gadget by pressing the tab key in the editor gadget but can't prevent the creation of an indent in the editor gadget. I tried using:

keybd_event_(#VK_BACK, 0 , 0 , 0)
keybd_event_(#VK_BACK, 0, #KEYEVENTF_KEYUP, 0)

to remove the indent but this doesn't work. Any suggestions?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
johnnyutah
User
User
Posts: 27
Joined: Sat Oct 16, 2004 1:25 pm

Post by johnnyutah »

I actually used the code in that post! However, it still causes a paragraph indent in the editor gadget when the tab key is pressed.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Sorry about that johnnyutah, I missed that part. How about this one then. It's for Win apps only.

Code: Select all

Procedure WinCallback(hWnd, msg, wparam, lparam) 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_NOTIFY 
      *pNMHDR.NMHDR = lparam 
      ; --> Is this our EditorGadget 
      If *pNMHDR\hwndFrom = GadgetID(0) 
        Select *pNMHDR\code 
          Case #EN_MSGFILTER 
            *pMSGFILTER.MSGFILTER = lparam 
            ; --> If the key pressed is the Tab key 
            If *pMSGFILTER\wparam = #VK_TAB 
              ; --> Activate next gadget 
              ActivateGadget(1) 
              ; --> Return non-zero to ignore the Tab key 
              result = 1 
            EndIf 
        EndSelect 
      EndIf 
  EndSelect 
  ProcedureReturn result 
EndProcedure 
      
If OpenWindow(0,0,0,322,170,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"EditorGadget") And CreateGadgetList(WindowID(0)) 
  SetWindowCallback(@WinCallback()) 
  EditorGadget (0,8,8,306,133,#PB_Container_Raised) 
  ; --> Tell the EditorGadget we want ot filter keyboard messages 
  ; --> We catch the events in the #WM_NOTIFY msg in our CallBack procedure 
  SendMessage_(GadgetID(0), #EM_SETEVENTMASK, 0, #ENM_KEYEVENTS) 
  ButtonGadget(1, 10, 140, 100, 20, "HI") 
  For a=0 To 5 
    AddGadgetItem(0,a,"Line "+Str(a)) 
  Next 
  Repeat 
    event = WaitWindowEvent() 
  Until event = #PB_Event_CloseWindow 
EndIf
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
johnnyutah
User
User
Posts: 27
Joined: Sat Oct 16, 2004 1:25 pm

Post by johnnyutah »

That works great - you're a genius!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

No, he's not. When the BUTTON is select, and you press tab to switch back to the textarea, the selection will snap you back to the button.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

@Trond: Thanks for pointing that out. I'll try one more time. ;)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Put this one through the ringer and see if I got it right this time. :)

Code: Select all

Procedure WinCallback(hWnd, msg, wparam, lparam) 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_NOTIFY 
      *pNMHDR.NMHDR = lparam 
      ; --> Is this our EditorGadget 
      Select *pNMHDR\hwndFrom
        Case GadgetID(0) 
          Select *pNMHDR\code 
            Case #EN_MSGFILTER 
              *pMSGFILTER.MSGFILTER = lparam 
              ; --> If the key pressed is the Tab key 
              If *pMSGFILTER\wparam = #VK_TAB And *pMSGFILTER\msg <> #WM_KEYUP
                Debug *pMSGFILTER\msg
                ; --> Activate next gadget 
                ActivateGadget(1) 
                ; --> Return non-zero to ignore the Tab key 
                result = 1
              EndIf 
          EndSelect
      EndSelect
  EndSelect 
  ProcedureReturn result 
EndProcedure 
Global currentGadget
If OpenWindow(0,0,0,322,170,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"EditorGadget") And CreateGadgetList(WindowID(0)) 
  SetWindowCallback(@WinCallback()) 
  EditorGadget (0,8,8,306,133,#PB_Container_Raised) 
  ; --> Tell the EditorGadget we want ot filter keyboard messages 
  ; --> We catch the events in the #WM_NOTIFY msg in our CallBack procedure 
  SendMessage_(GadgetID(0), #EM_SETEVENTMASK, 0, #ENM_KEYEVENTS) 
  ButtonGadget(1, 10, 140, 100, 20, "HI") 
  For a=0 To 5 
    AddGadgetItem(0,a,"Line "+Str(a)) 
  Next 
  Repeat 
    event = WaitWindowEvent() 
  Until event = #PB_Event_CloseWindow 
EndIf 
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

NOW you're a genius!
Randy Walker
Addict
Addict
Posts: 991
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Post by Randy Walker »

Trond wrote:No, he's not..."
Yes he is :D
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Hops on bandwagon:

Yes he is! :D
@}--`--,-- A rose by any other name ..
Post Reply