Page 1 of 1
Control left click
Posted: Sat Apr 20, 2019 7:27 am
by SkyManager
Could PB capture mouse with keyboard combination?
Such as mouse left click with control key pressing down.
Any PB example?
Re: Control left click
Posted: Sat Apr 20, 2019 11:55 am
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
Re: Control left click
Posted: Sat Apr 20, 2019 12:32 pm
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
Re: Control left click
Posted: Sat Apr 20, 2019 9:10 pm
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?!
Re: Control left click
Posted: Sun Apr 21, 2019 11:42 am
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
Re: Control left click
Posted: Sun Apr 21, 2019 7:39 pm
by davido
TI-994A wrote:
A slightly more basic example:
A very instructive example. Thank you.

Re: Control left click
Posted: Fri Apr 26, 2019 2:56 am
by SkyManager
hi TI-994A,
Is your suggestion for Window only?
Re: Control left click
Posted: Sat Apr 27, 2019 6:12 am
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.
