Call my application through keyword - keyboard

My problem is very simple, but implementation can be hard!
I want that my application (Windows Application:: Visual C# .net) is launched whenever the user uses some keys combinations (on his keyboard).
For example it types Ctrl+W+W and my application is launched, that's all, I want the simplest implementation, less code, memory...
Thanks :D

You would need to write a keylogger type application in conjunction with your app which monitors for keyboard events. Once your specific shortcut is triggered you could then load your application.
See here for information on how to capture keystrokes.

Create a shortcut to the application, and assign a hot-key combination to the shortcut. Depending on the O/S, not every keystroke combination can be assigned to a shortcut, e.g. you may be able to assign Ctrl+Alt+W but not Ctrl+W+W.

On Windows, you can create a shortcut (on the desktop) to your application.
When you open the properties of the shortcut, on the second tab (labeled "Shortcut"), you can assign a shortcut key. But you can use only Ctrl+Alt+key shortcuts.

I don't think this is possible in the way that you framed this question. What is possible, however, is to have your application run automatically on startup without showing any forms, have it hook into Windows to monitor all keystrokes (I'm not sure how to do that part, exactly) and then show a form when the user presses a particular sequence of keys.
So in other words, your application would have to be running from the time Windows starts, but only show itself (make a form visible) when the user clicks a particular key sequence.
Update: here is a link to an article that discusses how to do global keystroke capture using C#: http://blogs.msdn.com/toub/archive/2006/05/03/589423.aspx.

Related

Is there any way to unlock a password-protected computer using an AppleScript?

I'm trying to configure an automatic, Bluetooth-powered computer lock and unlock system. So far, I've got the lock script down, but I can't think of a script which would unlock the screen, as my comp is password protected. Any ideas?
You normally have two options when you're trying to script something. First, if the application is scriptable then you can issue applescript commands directly to the application. If it's not scriptable then your only other option is with GUI scripting where you simulate pressing buttons and typing keystrokes like if you were sitting in front of the computer doing it yourself. You use System Events commands to do this.
In your case I think you need the second option. In general when you gui script the application has to be frontmost. Since the "unlock screen" is probably frontmost at that moment you have a chance this will work. However I have not tried it so you'll need to do some testing to see if it's possible. Just do some searching for gui scripting examples and give it a try.
I would imagine your script will look something like the following. This assumes the cursor automatically is placed in the password section of the window so that the "keystroke" command will actually be typing in the proper place... otherwise you need to figure a way to put the cursor there before you type anything.
tell application "System Events"
keystroke "unlock password"
delay .5
click button "OK" of window 1
end tell

What window manager should I use as example?

I want to implement a simple specialized window manager for presentations (not user-controllable) that supports only the following operations:
Moving and resizing of windows
Switching desktops
Starting applications not on current desktop (in background) without disrupting current image.
I don't need any user input, button/titles, ...
What existing window manager should I use as example? There are many little "hello world" window managers, but they usually does not support desktop switching.
You don't need to reimplement the wheel.
openbox will do everything you mention and more besides.
Simply edit the rc.xml to disable the root menu, and re-launch.
Openbox also allows per app setting so that certain applications can open on a particular desktop by default, or with a particular size, or open hidden.
It also supports wildcards in the window selection, so that settings can apply to all windows.
devilspie2 is a window matching utility that can perform actions whenever a window opens.
It is highly hackable and the code is available on github. It will match windows by name/class/etc when they open, and perform actions on them. (including matching all windows and moving them to a different desktop. It will work with most window managers.
Based on the original devilspie which does not have Lua scripting, but is configured using s-exprs instead.
xdotool will also allow you to perform complex actions on windows without hacking any code. It will even fake user input (mouse/kbd) if you need it.
There are a few window managers written in Python that could be good starting points. Qtile and whimsy both describe themselves as hackable.

How can I insert text into another application?

To scratch a personal itch, I'm writing something like a cross between a character map and an on-screen keyboard. When the user selects a character, I'd like to insert it into another application, specifically, the application that would next receive focus if my application were closed. Is there any way to do this? Right now, I work around it by just putting the character into the clipboard and terminating, leaving the user to hit paste in the other application, but usage would be far more streamlined if I could just insert the text programmatically.
I'm doing this in GTK and expect to run it only on Linux. But cross-platform solutions are also appreciated, and if GTK can't do it but some other toolkit can, I'll gladly switch.
This sounds like you should use libwnck, which is a GTK-related library that lets you manipulate windows on the desktop. The documentation is a little sparse, but the function wnck_screen_get_previously_active_window() seems promising.
From a WnckWindow you can get an X window ID, and perhaps from there you can use the X libraries to send a paste message (or even send it a "Ctrl-V" keypress event), perhaps with XSendEvent().
Very good question, by the way. I wish I could answer it more knowledgeably.

How to create a mapped but not visible window with XLib?

I'm working on a I/O verification tool based on Linux in a game project. It is written in C++, and,since using the same I/O module as our game, it's based on OIS 1.2. Thus, though all I need is to print users' inputs on the console, I still need to create a window for OIS.
So here comes my question: How can I create a mapped window while it is still invisible and processes keyboard events?
I can't unmapped the window in that it won't process any keyboard event anymore. I also can't find function for show/hide a window.(maybe I search through a wrong diretion...)
My little tool works fine now except there is a stupid top-level empty window which needs to be focused for processing keyboard events...
Any advise is welcomed.
Thanks!!!
After reading this post: Linux/X11 input library without creating a window,
I realized my problem was that I misunderstood the philosophy of X11. All I need to do is simply pass the root window handle to OIS, and set the x11_grabkeyboard flag as true. The only drawback is maybe I can hardly debug my program with gdb since the keyboard is grabbed...
Though my situation is solved, there is one thing left.
Every article I read said an InputOnly window won't be visible and is capable for handling input events, while my InputOnly window is absolutely visible after mapped...
Maybe it's my Linux, or again, a misunderstanding...

How to change focus in X-Windows?

I am working on old Motif-based application for Linux. I want to be able to programmatically change the active window of our application. I can redirect the input by using XSetInputFocus() function and the keyboard input start to go there, but XReconfigureWMWindow() and XRaiseWindow() functions just don't work.
I've read that Window Managers try to stop this behaviour, so tried to disable configure redirection, but this doesn't work either. Any ideas how to make one of my own windows on top of the window stack?
There is a tiny program called wmctrl available (at least in Debian/Ubuntu it is in standard distribution) which is able to perform many operations on windows and desktops, and handles plenty of window managers. I'd suggest testing whether it works in your environment, and if so, peeking at its sources.
You may find the answer to this is dependent on the Window Manager the user is using, or even what settings they've given to the Window Manager. I like to set my Window Managers to do "focus follows mouse", which means you can't send the focus to a window that I haven't put my mouse on, unless you also warp the mouse there (is that function called XWarpMouse?).

Resources