disable certain key-behavior in EditorGadget

Just starting out? Need help? Post your questions and find answers here.
hss
User
User
Posts: 69
Joined: Thu Mar 08, 2007 6:02 pm

disable certain key-behavior in EditorGadget

Post by hss »

hello

how to stop certain keys--like #VK_UP--from being interpreted by EditorGadget?
in this example, the caret always jumps to last position--but, optimally, really nothing
should happen if #VK_UP gets pressed

Code: Select all

Global EditorNormalProc

Procedure.i EditorSubclassProc(hWnd, uMsg, wParam, lParam)

  If uMsg=#WM_KEYUP And wparam=#VK_UP
   p=Len(GetGadgetText(0))
   SendMessage_(GadgetID(0),#EM_SETSEL,p,p)  ;not-good attempt
  EndIf
  
  ProcedureReturn CallWindowProc_(EditornormalProc,hWnd,uMsg,wParam,lParam):
  
EndProcedure


       
OpenWindow(0,0,0,500,300,"")


EditorGadget(0,10,10,480,280)
Editornormalproc=SetWindowLong_(GadgetID(0),#GWL_WNDPROC,@EditorSubclassproc())   

For i=0 To 10
AddGadgetItem(0,i,"Line "+Str(i))
Next
  
p=Len(GetGadgetText(0))
SendMessage_(GadgetID(0),#EM_SETSEL,p,p)
SetActiveGadget(0)
  
  
Repeat : Until WaitWindowEvent(10)=#WM_CLOSE
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: disable certain key-behavior in EditorGadget

Post by srod »

Code: Select all

Procedure.i EditorSubclassProc(hWnd, uMsg, wParam, lParam)

  If (uMsg<>#WM_KEYUP And uMsg<>#WM_KEYDOWN) Or wparam<>#VK_UP
    ProcedureReturn CallWindowProc_(EditornormalProc,hWnd,uMsg,wParam,lParam):
  EndIf
EndProcedure
I may look like a mule, but I'm not a complete ass.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: disable certain key-behavior in EditorGadget

Post by MachineCode »

hss wrote:optimally, really nothing should happen if #VK_UP gets pressed
And why should nothing happen when the user presses the Up key to move up the text? It's an EditorGadget, for editing. Why are you forcing the user to not edit, then? Wrong gadget for the job, I assume?
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: disable certain key-behavior in EditorGadget

Post by srod »

I've done this in the past to mimic a console in a GUI etc.
I may look like a mule, but I'm not a complete ass.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: disable certain key-behavior in EditorGadget

Post by MachineCode »

Based on his example, it looks more like he wants a List[View|Icon]Gadget.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
hss
User
User
Posts: 69
Joined: Thu Mar 08, 2007 6:02 pm

Re: disable certain key-behavior in EditorGadget

Post by hss »

srod wrote:I've done this in the past to mimic a console in a GUI etc.
yay!
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: disable certain key-behavior in EditorGadget

Post by MachineCode »

:P
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: disable certain key-behavior in EditorGadget

Post by RASHAD »

Glad you are still around srod

Code: Select all

OpenWindow(0, 0, 0, 400, 300, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  AddKeyboardShortcut(0, #PB_Shortcut_Up, 10)
  EditorGadget(0, 10, 10, 380, 280)
  Repeat
    event = WaitWindowEvent()

Until event = #PB_Event_CloseWindow
Egypt my love
hss
User
User
Posts: 69
Joined: Thu Mar 08, 2007 6:02 pm

Re: disable certain key-behavior in EditorGadget

Post by hss »

nice one, RASHAD;

but.. how to only allow 'a' character?


this won't .. triggers, but still puts non-a-chars to Editor

Code: Select all

Procedure.i EditorSubclassProc(hWnd, uMsg, wParam, lParam)
  
  
  If (uMsg=#WM_KEYUP Or uMsg=#WM_KEYDOWN) And  wParam<>65
    Debug "everyhing but 'a' pressed"
    ProcedureReturn

  EndIf
  
    ProcedureReturn CallWindowProc_(EditornormalProc,hWnd,uMsg,wParam,lParam):
    
EndProcedure
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: disable certain key-behavior in EditorGadget

Post by RASHAD »

Hi hss

See next you allow any key
You can block any key

# 1

Code: Select all

Procedure Blockkey()
Debug Gadget
If GetActiveGadget() = 0
RemoveKeyboardShortcut(0, #PB_Shortcut_All)
AddKeyboardShortcut(0,#PB_Shortcut_Up, 10)
ElseIf GetActiveGadget() = 1
  For i = 32 To 90
   AddKeyboardShortcut(0, i,i)
   AddKeyboardShortcut(0,#PB_Shortcut_Shift | i,i+60)   
Next
  RemoveKeyboardShortcut(0, 65)
 EndIf
EndProcedure


OpenWindow(0, 0, 0, 400, 300, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 10, 10, 380, 250)
  StringGadget(1, 10, 270 ,380,20,"a")
  Repeat
  Select WaitWindowEvent()
      
       Case #PB_Event_CloseWindow
          Q = 1       
     
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 0
               Blockkey() 
           
           Case 1
               Blockkey()
                                          
          EndSelect
  EndSelect
Until Q = 1

Or
#2

Code: Select all

Global EditorNormalProc

Procedure.i EditorSubclassProc(hWnd, uMsg, wParam, lParam)
   Select uMsg
      Case #WM_KEYUP,#WM_KEYDOWN
        If  wparam=#VK_UP
          ProcedureReturn 0
        EndIf
        
      Case #WM_CHAR
        If wParam = 'A' Or wParam = 'a'
         ProcedureReturn 0
      EndIf
   EndSelect
   
   ProcedureReturn CallWindowProc_(EditorNormalProc,hWnd,uMsg,wParam,lParam)
 
EndProcedure


       
OpenWindow(0,0,0,500,300,"")

EditorGadget(0,10,10,480,280)
Editornormalproc=SetWindowLong_(GadgetID(0),#GWL_WNDPROC,@EditorSubclassproc())   

For i=0 To 10
AddGadgetItem(0,i,"Line "+Str(i))
Next
 
p=Len(GetGadgetText(0))
SendMessage_(GadgetID(0),#EM_SETSEL,p,p)
SetActiveGadget(0)
 
 
Repeat : Until WaitWindowEvent(10)=#WM_CLOSE

Egypt my love
Post Reply