iDevGames Forums
Receiving mouse clicks from different buttons - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Receiving mouse clicks from different buttons (/thread-7756.html)



Receiving mouse clicks from different buttons - Tobi - May 18, 2002 01:55 AM

I'm using the Classic/Carbon function Button() to get the state of the mouse button. However, this function returns true if any of the two buttons is down. And I want to support at least a two-button mouse in my game. On Macs a click with the right button is like a mouse click with the control key down. This way I can check whether the right or left mouse button is down. But if I click both the right and the left button, the left mouse button is ignored of course. Also if I click with the left button and hold the control-key down the game will think that the right button is clicked. Is there a way to get the state of the mouse buttons seperately?
I want to put the jump on the right mouse button and the gun shot on the left button, but with the current method the player would not be able to shoot when jumping.

Thanks in advance,

-Tobias


Receiving mouse clicks from different buttons - codemattic - May 18, 2002 10:15 AM

If you are willing to restrict your game to carbon, you should use carbon events. They will let you know which button is clicked, or even if the mouse wheel is moved (so you can zoom in your sniper scope for ex. - or maybe to change weapons!)

check out:
http://developer.apple.com/techpubs/macosx/Carbon/CarbonPortingTools/carbon_porting_guide/cpg_newtechstruct/An_Example__s_to_Sample.html and http://developer.apple.com/techpubs/macosx/Carbon/oss/CarbonEventManager/carboneventmanager.html

If you also want to support classic - maybe you could see if Input Sprockets supports multi-button mice.

good luck,

Codemattic


Receiving mouse clicks from different buttons - Deland - May 18, 2002 05:29 PM

Quote:Originally posted by codemattic
[b]If you are willing to restrict your game to carbon, you should use carbon events. They will let you know which button is clicked, or even if the mouse wheel is moved (so you can zoom in your sniper scope for ex. - or maybe to change weapons!)

Is there anything on Cocoa? Just wondering...


Receiving mouse clicks from different buttons - OneSadCookie - May 18, 2002 06:06 PM

Cocoa has documented support for three mouse buttons, and (I think as yet) undocumented support for up to 32. If you're interested, see the Omni Group's GDC sample code.


Receiving mouse clicks from different buttons - Deland - May 18, 2002 06:43 PM

Quote:Originally posted by OneSadCookie
Cocoa has documented support for three mouse buttons, and (I think as yet) undocumented support for up to 32. If you're interested, see the Omni Group's GDC sample code.

hmmm... Can't wait for that 32 Buttons USB Mouse to come out on Mac! Wink


Receiving mouse clicks from different buttons - Josh - May 18, 2002 07:55 PM

I can see it now... "Grr... I can never remember if button 27 updates my website or if that is button 14..." Cool


Receiving mouse clicks from different buttons - Tobi - May 20, 2002 12:22 AM

OK, thanks your help. My prog has now support for 3 buttons on OS X now using the Carbon Event Manager. For some reason Apple also put special functions just for Wacom Tablets inside their Framework, just because the Tablet Mouse does not consider itself a multi-button mouse. It submits 1 as the button code regardless of what button you click. The following method should work with nearly every multi-button mouse, but not with the tablet:
Code:
GetEventParameter (ev, kEventParamMouseButton, typeMouseButton, NULL, sizeof(EventMouseButton), NULL, &whichButton);
On Wacom devices whichButton is always 1 by default. (It is possible to hack the "Tablet Preferences" file inside /Users/Shared/Tablet to make it submit the correct button code. How this works is quite self-explanatory if you take a look at the file. But it seems impossible to do using the Tablet control panel application.). To get the state of the Wacom tablet mouse without having to hack the prefs call:
Code:
GetEventParameter (ev, kEventParamTabletEventType, typeUInt32, NULL, sizeof(UInt32), NULL, &whatTableEvent);

if (whatTableEvent==kEventTabletPoint)
{
TabletPointRec    tpr;
Boolean buttonStates[3];

GetEventParameter (ev, kEventParamTabletPointRec, typeTabletPointRec, NULL, sizeof(TabletPointRec), NULL, &tpr);

buttonStates[0]=tpr.buttons & 1;//Left button is in bit 0 of the buttons field
buttonStates[1]=tpr.buttons & 2;//Right button is in bit 1
buttonStates[2]=tpr.buttons & 4;//Middle buttons i in bit 2
}
(The code is totally uncomplete. You need to receive the event first and check if it is either "kEventMouseDown" or "kEventMouseUp". Also variable declarations are missing.)

Why can Apple not include a function like GetAsyncKeyState() on Windoze?
This is a cool combination of the Mac GetKeys() and Button() function which works perfectly with all keyboards and mice. Sad