Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi all,

I want to find something like System.Windows.Forms.SendKeys.SendWait(string); to send unicodechars & keys to focused window using MonoMac. I first tried to simulate key press but that is not what I am looking however event simulating key press bothered me alot(and after 3 days hard working, I finally found the answer). Simulating key press is not a good way because I can't simulate "a" when Caps Lock is on. I can't send Unicode characters because the fact is that Key press acts like the user presses a key on his keyboard.

I used System.Windows.Forms.SendKeys.SendWait in MonoMac (because System.Windows.Forms is ported to Mono) but did now worked. I checked the code and I figured out the SendKeys is not optimized to use on MAC OS X.

So I am really tired of searching and finding nothing useful.

Please help me in this way.

Regards,
PK DEVELOPER
Posted
Comments
Frank R. Haugen 15-Apr-12 5:28am    
The problem is that you are on a mac! Apple's platforms are a bitch to develop on. Have you considered using Java instead?
PK DEVELOPER 15-Apr-12 5:44am    
Dear Frank,
I really understand that developing for Apple's platforms (particularly Mac OS X) is catastrophic since the API and PInvokes are not documented good and furthermore, there is no any discipline in them. I developed all of my application stuff in Windows only in 2 hours but it is 5 days I am working on Apple's MAC OS X and not solved completely yet. I've first worked with Java's Robot. but MonoMac takes over. and the fact is that all of libraries use P/Invoke finally. So changing language is not reasonable. I found a solution for this problems and I am working on a Cross-Platform Library to gather all this input systems into one simple library to get rid of struggling with OS. But it requires a lot of time to gather all OS key codes and Input Systems. Windows is written only in 1 hour, Linux is written only in 1 day and MAC OS X is not finished yet.

About sending characters (just a bit similar to SendKeys.SendWait(string); ) I found the following approach only a few minutes ago.

var @event = NSEvent.KeyEvent(NSEventType.KeyDown, MacMouse.GetMouseLocation(), NSEventModifierMask.AlternateKeyMask, 1, 0, new NSGraphicsContext(), "a", "a", false, 0);

Native.CGEventPost (CGEventTapLocation.kCGSessionEventTap, @event.CGEvent);

Native.CFRelease (@event.Handle);

NOTE: MacMouse.GetMouseLocation() is in the library I am working on. so since I have not released my library yet, this class and function is not available. you can use NSEvent instead.
Frank R. Haugen 15-Apr-12 14:04pm    
I tried to sit down with a couple of Objective-C manuals but I got this intense urge to work on my novel, clean my apartment, and do other housework. Man I'm NEVER touching MAC development, except for Java -.-

1 solution

I don't know if the below will work on MonoMAC but it certainly works well on Windows. And it's free, and it's documented and other good stuff.

http://inputsimulator.codeplex.com/
 
Share this answer
 
Comments
PK DEVELOPER 16-Apr-12 1:24am    
It is one of the best open-source libraries for windows I have ever seen. And I first checked their CodePlex page to make sure whether they support Mac OS X as well Windows or not. and unfortunately they do not support it. this is the reason I am going to make a Cross-Platform Open-Source Library myself. But all my works are missing this solution. and I do not understand what should I do :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900