Polling the keyboard in Cocoa - objective-c

My Cocoa application should react continuously to the state of the keys pressed by the user. To that end, I would like to poll the keyboard at fixed intervals, instead of relying on keyboard events. Is there any Cocoa API to achieve this? If not, what other options exist?

Polling is never such a great idea. You shouldn't have to do that in most cases.
There is 2 API you may be interested for:
Quartz Event Taps https://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html
IOKit HID API https://developer.apple.com/library/mac/#documentation/DeviceDrivers/Conceptual/HID/intro/intro.html#//apple_ref/doc/uid/TP40000970
Please note keyboard accesses may pose some security issues so the system may not allow you to read the keyboard state. Check the Accessibility settings (access to assistive devices).

Don't poll the keyboard, just implement -keydown: in your App delegate class.

Related

Disabling Siri in an app

Is there any way to completely disable Siri within the app? I am not only talking about the proximity sensor, but the long-press on the home key as well.
Thanks.
No. It's impossible to override the functionality of the home button. In general, Apple does not allow you to modify the behavior of something that is outside of the scope of your app.

How do I Capture keyboard/mouse events with my application in focus?

I'm building a synergy like app for Mac OS, that captures keyboard/mouse and sends them to a remote computer.
I wish to capture all user keyboard and mouse events, while my NSWindow is in focus (if possible, while not in focus would be nicer). the catch is - I don't want system shortcuts like CMD+Tab or CMD+Q to interrupt me, I wish to handle them before the windowing system does, so that my app won't loose focus. Same for mouse.
Thanks
Check this - Cocoa Event-Handling Guide
Hope this helps :)

How to detect external keyboard connectification in objective-c?

My application need to know are external keyboard connect or no. How could i do to know that? No Private API please. :)
If this is iOS related, I'm not sure why you'd want to detect this as the hardware keyboard acts exactly the same as the software keyboard (except with a few extra shortcuts for sound, brightness etc. which your app shouldn't use anyway).
If you're considering screen space, then the software keyboard will still send it's notifications when it is displayed or when it is hidden, so you can respond to those. For example, say you have the software keyboard up and then you connect your external keyboard. The software keyboard will hide, and will post the UIKeyboardWillHideNotification. So you can respond to that.

How to mute the incoming call with single touch programatically in iphone sdk

I am having a mute button in my app,when an incoming call comes when I tap on to that button the incoming call's ringtone should become mute.
Can anyone suggest me how to do this programatically.
Thanks to all,
Monish.
Applications cannot alter core functionality of the device. As such, you cannot interfere with the phone capabilities. Therefore, what you are asking for is not possible.
I am, of course, assuming that you haven't jailbroken your phone.

How to be notified in OS X when a drag operation *starts* anywhere?

I'm wondering if there's any way to have my application be notified when a drag-and-drop operation starts anywhere on the screen, even if I don't have an active window there.
I've looked into the normal drag-and-drop APIs, but I haven't spotted anything that does this. The NSDraggingDestination protocol along with the -[NSWindow/NSView registerForDraggedTypes:] method allows you to notice when someone is dragging something and that crosses over into your window, but I'd like to notice it when any dragging operation is started anywhere on the screen.
Any tips on how to go about this? Is there a standard Cocoa API for it, or is there a private API / some kind of dirty hack to get this information?
Thanks in advance :)
Take a look at NSEvent’s +addGlobalMonitorForEventsMatchingMask:handler:. I’m not sure if you can track mouse dragging but it’s certainly possible to track mouse button up/down events.
i haven't done it,
but i am assuming you need some kind of external software monitoring ALL mouse activity on the system, and reporting it to your app (or your application doing this itself),
as dragging events are usually reported in your app only when there is activity inside your app's window..