[Mono-dev] AppActivate and System.Windows.Forms.SendKeys on Ubuntu 10.10

Quandary quandary82 at hailmail.net
Mon Mar 21 21:08:53 EDT 2011

To make a long mail short, that's incorrect.

When you look at xvkbd-3.0, focus a window and simulate alt+f4, it
closes, and with simulated alt + tab, it switches windows.

Looking at its sources, it's not working with XSendEvent there however,
it uses some magic in libxtst, which however, just all comes back to
some wrapping around base X11 calls.

I didn't look any closer at it, as I don't deem ALT+TAB and ALT+F4 as
important in respect to SendKeys.
Sending key combinations + key modifiers (ALT/CTRL) to other application
however, is.

Thus I attached fixme.c, a basic key dispatch implementation for
Linux/X11 in C using XSendEvent.
It's probably still a bit buggy, especially in respect to
"UNICODE"/KeyboardInternationalization (not really important in this
respect IMHO).
I'll probably port it to CS next weekend.

Note that it also contains an AppActivate implementation for Linux !
(It doesn't yet switch to the appropriate workspace, but fixing that is
rather simple, but unfortunately time-consuming, and as I don't need it,
I have just commented that part out for now)
AppActivate for Windows is simple, just pinvoke SetActiveWindow.

I don't have a Mac, but the simplest way to activate a window there I
found to be so easy I can implement it blindly:

[System.Runtime.InteropServices.DllImport("libc", EntryPoint = "system")]
internal extern static int system(string strCommand);

Note that in the below C snippet, one would still need to check for
malicious \n\r or semicolons when the application title is being
supplied as parameter.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[])
    system("osascript -e \"tell application \\\"Address Book\\\" to
    return EXIT_SUCCESS;

On 03/17/2011 03:19 AM, Jonathan Pryor wrote:
> Now, what does X11 provide? A cursory glance shows XSendEvent:
> 	http://tronche.com/gui/x/xlib/event-handling/XSendEvent.html
> This allows passing an XEvent, such as an XKeyEvent, to a given window.
> Problem: In Windows, it's the operating system which handles the input, which thus allows OS "capturing" of Alt+Tab so that the active application is switched. In X11, XSendEvent() requires that you explicitly specify both the Display and Window that the event is being passed to. Consequently, there is NO MECHANISM to have Alt+Tab "captured" by the OS and thus change windows (even if Alt+Tab _will_ change windows when typed via the keyboard). This is because the WIndow Manager is grabbing Alt+Tab, but the Window Manager is a completely separate process, and there's not necessarily an easy way to grab the Display+Window for the Window Manager (which might not have a Window to begin with).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110322/8a72421a/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fixme.c
Type: text/x-csrc
Size: 11821 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110322/8a72421a/attachment-0001.bin 

More information about the Mono-devel-list mailing list