Page 1 of 1

Preventing use of tab key in EditorGadget

Posted: Sat Jun 04, 2005 6:59 pm
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?

Posted: Sat Jun 04, 2005 7:02 pm
by Sparkie

Posted: Sat Jun 04, 2005 8:45 pm
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.

Posted: Sat Jun 04, 2005 9:57 pm
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

Posted: Sun Jun 05, 2005 4:19 pm
by johnnyutah
That works great - you're a genius!

Posted: Sun Jun 05, 2005 4:58 pm
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.

Posted: Sun Jun 05, 2005 5:53 pm
by Sparkie
@Trond: Thanks for pointing that out. I'll try one more time. ;)

Posted: Sun Jun 05, 2005 6:08 pm
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

Posted: Sun Jun 05, 2005 6:30 pm
by Trond
NOW you're a genius!

Posted: Mon Jun 20, 2005 11:26 pm
by Randy Walker
Trond wrote:No, he's not..."
Yes he is :D

Posted: Tue Jun 21, 2005 12:06 am
by Dare2
Hops on bandwagon:

Yes he is! :D