Re: How do I tell if the mouse button is down, independent of view, etc.?
Re: How do I tell if the mouse button is down, independent of view, etc.?
- Subject: Re: How do I tell if the mouse button is down, independent of view, etc.?
- From: Ryan Poling <email@hidden>
- Date: Sun, 9 Mar 2008 08:59:01 -0700
It depends if you need to be notified when someone presses the button
(or key), or if you just need to check whether it's currently down or
not.
If you want to be notified when they press the mouse button globally,
look up CGEventTapCreate in the Xcode documentation. This could
either be implemented in a helper app which runs in the background, or
if your app will always be running when you want the notification, you
can just do it directly within your app. You'll receive a callback
whenever the mouse button is pressed.
-Ryan
<http://www.chimoosoft.com/>
On Mar 8, 2008, at 11:50 PM, Dave Hersey wrote:
Chris,
I think you'll need to put some Carbon in your Cocoa to get what you
want.
If you need to get that information systemwide (ie. when you're in
the background too), you can use Carbon's GetCurrentButtonState()
for the mouse and maybe Carbon HotKey APIs for the keypresses. You
can register the hot key handlers from your Cocoa app, and there are
even some tutorials that come up in Google.
Hotkeys are only going to give you the key presses you register for,
though... If you need to get notified when *any* key is pressed
system-wide, I don't think you can handle that from within the app
itself. I'd expect you'd need to write a helper to notify your app.
Someone else may know better.
- d
On Mar 9, 2008, at 1:20 AM, Christopher Kempke wrote:
I'm working on some code for a client, whose users (handicapped
children, mainly) are using non-standard mousing devices. These
are (often literally) single-switch input devices: there's no
notion of position with them at all, basically just a mouse button
sans actual mouse. (On-screen position is obtained by a variety of
complicated mechanisms, including simple scanning, where the user
pushes/blinks/speaks/blows into a tube/whatever at the appropriate
time, the exact input being dependent on their capabilities.
Pretty much all of these devices just turn the "input," whatever it
is, into a mouse click or keypress).
A fairly common problem that comes up is simply knowing if the
mouse button is down or not. I'm looking for the Cocoa
equivalent of the deprecated QuickDraw "Button()" function -- just
tell me whether (a particular or even just any) mouse button is
currently pressed or not.
Mousedown handlers don't seem to be doing it for me, because I
don't know what to put them on: I need to know whether the mouse
is down regardless of modality, what window's in front, where the
cursor is, and even whether or not the mouse is in one of my app's
windows at all. I could live with keeping track of every mouse
down and up, so long as there's a way to do it globally (even while
in the background).
I'm guessing this has come up before, but searching for "Button()"
isn't helping. Any hints? I'll eventually need the same thing
for keystrokes (the equivalent of deprecated GetKeys()), too, so
I'd take hints there, as well.
--Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
@chimoosoft.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden