Could PB capture mouse with keyboard combination?
Such as mouse left click with control key pressing down.
Any PB example?
Control left click
-
- Enthusiast
- Posts: 339
- Joined: Tue Jan 30, 2007 5:47 am
- Location: Hong Kong
Re: Control left click
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
A slightly more basic example:SkyManager wrote:Could PB capture mouse with keyboard combination?
Such as mouse left click with control key pressing down...
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
-
- Enthusiast
- Posts: 339
- Joined: Tue Jan 30, 2007 5:47 am
- Location: Hong Kong
Re: Control left click
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?!
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
Not natively.SkyManager wrote:...Can StringGadget do similar action?!
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
Re: Control left click
A very instructive example. Thank you.TI-994A wrote: A slightly more basic example:
DE AA EB
-
- Enthusiast
- Posts: 339
- Joined: Tue Jan 30, 2007 5:47 am
- Location: Hong Kong
Re: Control left click
hi TI-994A,
Is your suggestion for Window only?
Is your suggestion for Window only?
Re: Control left click
Yes, Windows only. The SetWindowLongPtr(), CallWindowProc(), and GetAsyncKeyState() functions and the #MK_XXXXXX constants are from the Windows API.SkyManager wrote:Is your suggestion for Window only?
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.
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