Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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 13-Apr-12 23:09pm
Comments
Frank Reidar Haugen at 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 at 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 Reidar Haugen at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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/
  Permalink  
Comments
PK DEVELOPER at 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
0 OriginalGriff 220
1 ProgramFOX 120
2 Richard MacCutchan 100
3 kbrandwijk 90
4 ChauhanAjay 80
0 Sergey Alexandrovich Kryukov 9,050
1 OriginalGriff 8,151
2 CPallini 2,613
3 Richard MacCutchan 2,221
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 15 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100