Control left click

Just starting out? Need help? Post your questions and find answers here.
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Control left click

Post by SkyManager »

Could PB capture mouse with keyboard combination?
Such as mouse left click with control key pressing down.
Any PB example?
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

Re: Control left click

Post by wombats »

Here is an example with the CanvasGadget():

Code: Select all

Procedure OnCanvasClick()
  Protected mx, my
  mx = GetGadgetAttribute(0, #PB_Canvas_MouseX)
  my = GetGadgetAttribute(0, #PB_Canvas_MouseY)
  If GetGadgetAttribute(0, #PB_Canvas_Modifiers) & #PB_Canvas_Control
    If StartDrawing(CanvasOutput(0))
      Circle(mx, my, 2, RGB(0, 0, 255))
      StopDrawing()
    EndIf
  EndIf
EndProcedure
OpenWindow(0, 0, 0, 320, 240, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 320, 240)
BindGadgetEvent(0, @OnCanvasClick(), #PB_EventType_LeftClick)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Control left click

Post by TI-994A »

SkyManager wrote:Could PB capture mouse with keyboard combination?
Such as mouse left click with control key pressing down...
A slightly more basic example:

Code: Select all

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
If OpenWindow(0, 0, 0, 500, 350, "Keyboard/Mouse Combination", wFlags)
  CanvasGadget(1, 0, 50, 500, 300, #PB_Canvas_Keyboard)
  TextGadget(0, 0, 10, 500, 30, "", #PB_Text_Center)
  Repeat
    event = WaitWindowEvent()
    Select event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            Select EventType()
              Case #PB_EventType_LeftButtonDown, #PB_EventType_RightButtonDown
                mouseKeyCombination.s = ""
                If GetGadgetAttribute(1, #PB_Canvas_Modifiers) & #PB_Canvas_Control
                  mouseKeyCombination + "ctrl + "
                EndIf       
                If GetGadgetAttribute(1, #PB_Canvas_Modifiers) & #PB_Canvas_Alt
                  mouseKeyCombination + "alt + " 
                EndIf    
                If GetGadgetAttribute(1, #PB_Canvas_Modifiers) & #PB_Canvas_Shift
                  mouseKeyCombination + "shift + "
                EndIf                
                If EventType() = #PB_EventType_LeftButtonDown
                  mouseKeyCombination + "left click..."
                Else
                  mouseKeyCombination + "right click..."
                EndIf                
                SetGadgetText(0, mouseKeyCombination)
            EndSelect
        EndSelect
    EndSelect
  Until event = #PB_Event_CloseWindow
EndIf
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Re: Control left click

Post by SkyManager »

Thanks for the reply.

Obviously Canvas has a #PB_Canvas_Keyboard control that allows us to do that.

But I cannot find any #PB_Keyboard for StringGadget.

Can StringGadget do similar action?!
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Control left click

Post by TI-994A »

SkyManager wrote:...Can StringGadget do similar action?!
Not natively.

Code: Select all

hideStringGadgetContextMenu = #True

Procedure gadgetProc(hWnd, uMsg, wParam, lParam)
  Shared origProc, hideStringGadgetContextMenu
  
  mouseKeyCombination.s = ""  
  If wParam & #MK_CONTROL
    mouseKeyCombination + "ctrl + "
  EndIf       
  If wParam & #MK_SHIFT  
    mouseKeyCombination + "shift + "
  EndIf 
  If GetAsyncKeyState_(#VK_MENU) & $8000
    mouseKeyCombination + "alt + " 
  EndIf    
  
  Select uMsg
    Case #WM_LBUTTONDOWN
      mouseKeyCombination + "left down..."
      SetGadgetText(0, mouseKeyCombination)
    Case #WM_RBUTTONDOWN
      mouseKeyCombination + "right down..."   
      SetGadgetText(0, mouseKeyCombination)
      If hideStringGadgetContextMenu
        uMsg = 0
      EndIf      
  EndSelect  
  
  ProcedureReturn CallWindowProc_(origProc, hWnd, uMsg, wParam, lParam)
EndProcedure

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered 
OpenWindow(0, 0, 0, 600, 200, "Keyboard/Mouse Combination (Win32 API)", wFlags)
StringGadget(0, 10, 10, 580, 30, "") 
origProc = SetWindowLongPtr_(GadgetID(0), #GWL_WNDPROC, @gadgetProc())
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend 
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Control left click

Post by davido »

TI-994A wrote: A slightly more basic example:
A very instructive example. Thank you. :D
DE AA EB
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Re: Control left click

Post by SkyManager »

hi TI-994A,

Is your suggestion for Window only?
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Control left click

Post by TI-994A »

SkyManager wrote:Is your suggestion for Window only?
Yes, Windows only. The SetWindowLongPtr(), CallWindowProc(), and GetAsyncKeyState() functions and the #MK_XXXXXX constants are from the Windows API.

For MacOS, the gadgets must be sub-classed in order to intercept mouse events. And for Linux, the mouse events are global, and not isolated to any single gadget (IINM).

If you're interested in exploring these options, I could cobble up some examples. :D
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply