I am creating a virtual keyboard for my application via Input Method Kit (IMK).
However I am not able to simulate a keyboard event by pressing a button.
Is there any library I can used for keyboard event simulation?
Are there any reference materials/solutions for this problem?
See the IMKTextInput Protocol Reference, you need to call insertText:replacementRange:
[client insertText:text replacementRange:NSMakeRange(NSNotFound, NSNotFound)];
where text is an instance of NSString.
Related
I want to run a program (exe file) when the Power button of my laptop is pressed. (Not when system is shutting down)
I tried getting its keycode using c# and js, but none of them capture this keypress as they only capture keyboard buttons. Look at the drop-down menu I have opened:
My problem would be solved if they add "Run a specific program..." in this drop-down:
But of course they won't add this option!
So, how do I get it done? Maybe using Task Scheduler?
There's no keycode for the power button. The driver is sitting between your OS and your hardware. When you push the "G" button on your keyboard, the driver translates that to an OS system call representing the "G" key which your program can listen for and intercept. But there's no OS system call for a representing the "power" button. Instead, your driver is translating that to OS system calls to initiate a shutdown, turn off the monitor, etc.
Your laptop driver allows you to configure which system call you want to initiate when the power button is pressed, but that driver is going to be unique to the brand and model of your laptop, and if they don't offer support for capturing that keypress through their driver, then you probably don't have any easy way to intercept it.
I'm developing an app using wxpython for use specifically with a Microsoft surface, which requires text input. Is there a way to automatically bring up the onscreen keyboard when an input box is selected?
You can create an onscreen keyboard with wxPython for your applications. If you want keyboard to appear when you click your app's wx.TextCtrl, you just need to bind wx.EVT_LEFT_DOWN and/or wx.EVT_LEFT_UP events to it. However, if you want keyboard to appear when any app's input is clicked then it is really hard to achieve, instead you can assign a function key to popup.
I am trying to get a global keyboard hook for OSX 10.10.3. It would ideally be neatly packaged in a Java library, but at this point I just want something that works.
I've tried two routes, and both produce the same results: I am able to read touchpad activity, external mouse activity, and keypresses of the "control", "option", "command", and "shift" keys. Keypresses on all other keys do not trigger any activity.
Both JNativeHook and a native application using quartz event taps produce that result, so I assume at some level they hit the same API. Is there somewhere else I should be looking?
Another way is the Cocoa method +[NSEvent addGlobalMonitorForEventsMatchingMask:handler:]. For either this or event taps to see keyboard events, your app must be "trusted for accessibility access". For instance look up AXIsProcessTrustedWithOptions.
I want to make an Cocoa aplication that take input from keyboard and does specific actions, depends on which button is pressed. What function(or anything) shoud I use?
Check the NSResponder class documentation and there keyDown.
I need to simulate a button press on my Cocoa button programatically and I am trying to do this on cocotron which unfortunately does not have the NSEvent method: mouseEventWithType:location:modifierFlags:timestamp:windowNumber:context:eventNumber:clickCount:pressure:
implemented. Is there anyway to programatically simulate a button press without having to create an event?
Don't forget to look in superclasses when you're looking for something. All NSControls, including all NSButtons, respond to a performClick: message.
That said, is it really appropriate for you to simulate a button press? If you just want something done, it's generally better to directly tell the controller to do it.