It is currently Thu Jun 20, 2013 3:41 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Re: Opening a PopupMenu correctly on MacOS
PostPosted: Wed Nov 24, 2010 10:10 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 821
Location: Germany
Andre wrote:
Is there any possibility on MacOS to recognize a right-mouseclick in an empty (!) window, means without adding (dummy) imagegadgets or similar?

Code:
#kEventClassMouse = 'mous'
#kEventMouseButtonPrimary = 1
#kEventMouseButtonSecondary = 2
#kEventMouseButtonTertiary = 3
#kEventMouseDown = 1
#kEventParamKeyModifiers = 'kmod'
#kEventParamMouseButton = 'mbtn'

#typeMouseButton = 'mbtn'
#typeUInt32 = 'magn'

ImportC ""
  GetEventClass(Event)
EndImport

Structure EventTypeSpec
  EventClass.L
  EventKind.L
EndStructure

Procedure EventHandler(*NextEventHandler, Event, UserData)
  Select GetEventClass(Event)
    Case #kEventClassMouse
      Select GetEventKind_(Event)
        Case #kEventMouseDown
          If GetEventParameter_(Event, #kEventParamMouseButton, #typeMouseButton, 0, 4, 0, @ButtonType) = 0
            If GetEventParameter_(Event, #kEventParamKeyModifiers, #typeUInt32, 0, 4, 0, @KeyModifier) = 0
              Select ButtonType
                Case #kEventMouseButtonPrimary
                  If KeyModifier = $00001000
                    Debug "Right mouse button"
                  Else
                    Debug "Left mouse button"
                  EndIf
                Case #kEventMouseButtonSecondary
                  Debug "Right mouse button"
                Case #kEventMouseButtonTertiary
                  Debug "Middle mouse button"
              EndSelect
            EndIf
          EndIf
      EndSelect
  EndSelect

  If *NextEventHandler
    CallNextEventHandler_(*NextEventHandler, Event)
  EndIf
EndProcedure

OpenWindow(0, 100, 100, 400, 200, "Detect left, middle and right mouse button click")

EventHandlerUPP = NewEventHandlerUPP_(@EventHandler())
EventCount = 1
Dim EventTypes.EventTypeSpec(EventCount - 1)
EventTypes(0)\EventClass = #kEventClassMouse
EventTypes(0)\EventKind = #kEventMouseDown
InstallEventHandler_(GetWindowEventTarget_(WindowID(0)), EventHandlerUPP, EventCount, @EventTypes(), UserData, @EventHandlerRef)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow


Last edited by Shardik on Thu Nov 25, 2010 8:52 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Opening a PopupMenu correctly on MacOS
PostPosted: Wed Nov 24, 2010 10:58 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 921
Location: Germany (Saxony, Deutscheinsiedel)
Thanks Shardik, that works! :D

Even if it would be better, if that event handling would native in PB... :twisted:

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
 
 Post subject: Re: Opening a PopupMenu correctly on MacOS
PostPosted: Thu Nov 25, 2010 1:39 am 
Offline
Addict
Addict
User avatar

Joined: Mon Aug 04, 2008 10:56 pm
Posts: 851
Location: Seattle, USA
Odd, if I use my trackball with a right button Shardik's code works but if I use the 'ctrl'+(mousepad) button I get a left-click. In other words, if I use my MBP without an external mouse and try to right click.. I get only left-clicks. This limitation may be a problem for some users.

_________________
MacBook Pro/Retina, OSX 10.8.3 Mountain Lion, PB-5.11x64


Top
 Profile  
 
 Post subject: Re: Opening a PopupMenu correctly on MacOS
PostPosted: Thu Nov 25, 2010 8:51 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 821
Location: Germany
WilliamL wrote:
Odd, if I use my trackball with a right button Shardik's code works but if I use the 'ctrl'+(mousepad) button I get a left-click.

You are right William, I didn't take care in my code example for using a left click in
combination with the Ctrl key as a right mouse click (presumably for those Apple users
with a one button mouse) although I had already read a posting from David McLeod in
the apple mailing list where he presented C code which demonstrates how to analyse
modifier keys and mouse clicks.

I have therefore updated my above code example. You are now free to use the Ctrl or Alt
or Cmd key together with the left mouse button to produce a right click... :wink:

I have tested my above example with an iMac and Mac OS X 10.6.5, a mighty mouse and
an USB Wheel mouse on which pressing the wheel down is correctly interpreted as a middle
button click.


Top
 Profile  
 
 Post subject: Re: Opening a PopupMenu correctly on MacOS
PostPosted: Thu Nov 25, 2010 9:06 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Aug 04, 2008 10:56 pm
Posts: 851
Location: Seattle, USA
Thanks Shardik,

Works perfectly on my MBP in 10.5.8. :D

(added to API list)

_________________
MacBook Pro/Retina, OSX 10.8.3 Mountain Lion, PB-5.11x64


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye