Mouse button not working in screens in OS X

Mac OSX specific forum
jjsonick
New User
New User
Posts: 2
Joined: Mon Mar 25, 2013 3:18 pm

Mouse button not working in screens in OS X

Post by jjsonick »

On Mac for me, PureBasic recognizes mouse clicks as expected with Windows/Gadgets, but it seems to ignore mouse clicks when using a Screen instead. I have read that there's issues with right-click sometimes on Mac, but this is left-click, too.

For instance, I run the included Gadget.pb example (Window based gadgets) and clicks work fine, but when I run Mouse.pb (Screen based), the logo graphic moves with the mouse as expected, but it is impossible to exit the running program, as left-clicks are ignored. I had to add "KeyboardPushed(#PB_Key_Escape)" as the Until condition to get the example not be be stuck in its Repeat loop.

I'm on a MacBookPro, OS X 10.7.5, using v5.10 Revision: 1472 64-bit version (the demo). I tried with both trackpad and a usb Logitech mouse - same results. With a Screen, mouse movement registers, clicks do not.

I altered the Mouse.pb to be a bit shorter to demonstrate this. Position of logo should change when left-click, but does not. Can others take a look at this and the original Mouse.pb to confirm? Thanks!

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Mouse example file
;
;    (c) 2001 - Fantaisie Software
;
; ------------------------------------------------------------
;

If InitMouse() = 0 Or InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Can't initialize", 0)
  End
EndIf

;
;-------- MessageReq and OpenScreen --------
;

MessageRequester("Information", "This will test the fast mouse access..."+Chr(10)+"Press esc to quit!", 0)

If OpenScreen(1024, 768, 32, "Mouse") = 0
  MessageRequester("Error", "Impossible to open screen",0)
  End
EndIf

;
;-------- Init and Load Stuff --------
;

x = 100
y = 100

LoadSprite(0, "Data/PureBasic.bmp", 0)   ; Load nice small Logo

;
;-------- MainLoop --------
;

Repeat
  FlipBuffers()                        ; Flip for DoubleBuffering
  ClearScreen(RGB(0,0,0))                   ; CleanScreen, black

  ExamineKeyboard()
  ExamineMouse()                      
          
  x = MouseX()                         ; Returns actual x pos of our mouse
  y = MouseY()                         ; Returns actual y pos of our mouse
  
If MouseButton(#PB_MouseButton_Left)
  MouseLocate(400, 300)
EndIf

DisplaySprite(0, x-SpriteWidth(0)/2, y-SpriteHeight(0)/2)


Until KeyboardPushed(#PB_Key_Escape)

End 
jamirokwai
Addict
Addict
Posts: 802
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: Mouse button not working in screens in OS X

Post by jamirokwai »

I confirm this behavior (Mountain Lion, PB 5.10x86). The mouse-button does not fire.
Regards,
JamiroKwai
User avatar
Shardik
Addict
Addict
Posts: 2076
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Mouse button not working in screens in OS X

Post by Shardik »

After changing

Code: Select all

LoadSprite(0, "Data/PureBasic.bmp", 0)
to

Code: Select all

LoadSprite(0, #PB_Compiler_Home + "Examples/Sources/Data/PureBasic.bmp", 0)
the code example posted by jjsonick can be executed without errors. And furthermore I can confirm that the detection of a left mouse click does not work in MacOS X 10.6.8 (Snow Leopard) with the Cocoa framework (default) in PB 5.11 x86. But if setting the subsystem in "Compiler/Compiler Options..." to "Carbon" the detection of the left mouse button works like a charme... :wink:
jjsonick
New User
New User
Posts: 2
Joined: Mon Mar 25, 2013 3:18 pm

Re: Mouse button not working in screens in OS X

Post by jjsonick »

Shardik wrote:After changing

Code: Select all

LoadSprite(0, "Data/PureBasic.bmp", 0)
to

Code: Select all

LoadSprite(0, #PB_Compiler_Home + "Examples/Sources/Data/PureBasic.bmp", 0)
the code example posted by jjsonick can be executed without errors.
Ah, sorry about that - I had saved this altered version of mouse.pb in the Examples/Sources directory, so it worked as is there.

Thanks for testing and confirming, Shardik and jamirokwai!

Can this thread be moved to the Bugs-Mac OSX forum? Or should I just make a new post there?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3944
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Mouse button not working in screens in OS X

Post by wilbert »

For OS X 10.6+ with PB 5.10+ you can use this as a workaround

Code: Select all

If CocoaMessage(0, 0, "NSEvent pressedMouseButtons") = 1; check for left mouse button
  MouseLocate(400, 300)
EndIf
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply