In a GUI application? You really need to say things like this when you raise the question - none of the answers above will help with this as it is completly different problem then passing text around in a terminal.
Instead what you want is xdotool to inject keyboard input into an X11 application.
I use xbindkeys for any keybindings that I want across all DE/WMs. You should be able to write a script to focus on the window using the packages wmctrl and xdotool (in the community repos) and bind them to the key of your choosing with xbindkeys.
To view all windows:
wmctrl -l
To focus and raise up a window, even on another desktop (xdotool)
windowactivate windowId
Xdotool is super powerful, and well documented.
A good resource for wmctrl
I highly recommend giving xbindkeys a try, you can set up some really interesting commands. For instance, my mouse has an "alt" button, so alt + rolling the mouse wheel adjusts my volume. Using the xclip package you can use what is on your clipboard, Alt+S attempts to open the url I just saved to my clipboard with mpv.
> OSX's open(1) has a -g flag to open a program without stealing focus, and thats what I use. xdg-open has no equivalent flag, so I just use it plain. I just wish there was a way to do the same in Linux, is all.
There's xdotool, which can send various X events, including window management events. E.g. here is how to focus some window. Something like xdotool search --pid $VIM_PID behave %@ blur windowactivate
(or windowfocus
) right before you call xdg-open should work 99.9% of the time. It'll keep refocusing vim when it loses focus, just remember to kill it after few milliseconds because it'll make focusing any other window impossible. :)
You can try reporting a bug against xdg-open, it looks like a quite useful feature and would be quite easy to add — wait for the first window opened by given pid and immediately defocus it. Though the devs might not like this particular solution because pretty messy :) unfortunately I can't think of a better one.
I'm afraid I did not. Unfortunately it seems to be a bug inside the keyboard itself.
I just tried to create a cheap fix mapping PU/PD to HOME/END with xdotool, but this creates a circular reference - so it doesn't work... I might give a more low level keymapping a go next week. This, of course, is all Linux specific...
Or maybe I will just not bother with changing PU/PD and bind some key combination to send Ctrl+Shift+Home/End instead... In Windows you could probably use AutoHotkey for this.
http://www.semicomplete.com/projects/xdotool/ for creating "shell macros" for UI interaction.
Simple guis by using kdialog or zenity. It's no problem to use scripts using one on a different DE as long as all the dependencies for either kdialog or zenity are installed.
In addition to what /u/dangersalad salad suggested (i.e., using dmenu), you might also look at xdotool:
http://www.semicomplete.com/projects/xdotool/
I've found the combination of xdotool and dmenu quite useful.
Might be possible using xdotool or maybe tint2 also provides some way.
You should try asking either in the crunchbang forums or in the arch or gentoo forums.
I use xmonad but have only dabbled in haskell programming. It's certainly possible and I doubt it would be particularly difficult. (Edit: looks like it's as easy as I thought but you only get a limited type of communication back and forth, you can send in predefined commands and you can get events from the loghooks but you can't just query an api for state and send it complex commands)
I don't have any specific advice for you unfortunately but it seems like you would want to look into the main function in your xmonad.hs file and start your webserver up there and then look into the http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-ServerMode.html hook to allow your webserver process to communicate with xmonad.
You could also use something like http://www.semicomplete.com/projects/xdotool/ to let your webserver just pretend to be a keyboard/mouse. It's hacky but maybe it's good enough for what you want to do.
Whatever you figure out I would be interested in how it turns out.
Here is an interesting old discussion I found that helped me understand why this is harder than it should be: http://www.digipedia.pl/usenet/thread/14422/9850/
If you are ambitious then you should find some way to allow xmonad to listen for messages from other sources instead of blocking in the X event loop and then this would be much much easier. That's alluded to at the end of the thread I just linked.
edit: all of this info is from 2008 so if things are different now please correct me. Now i'm thinking of some cool things I could do with this.
I would use xdotool.
Alternatively, you could bind a shortcut to use xsel to put whatever you want in your paste buffer and use Ctrl+V to paste.
xdotool is something that emulates mouse events, including clicking a specific point at the screen, or at coordinates relative to a given window.
http://www.semicomplete.com/projects/xdotool/xdotool.xhtml#mouse_commands
or you could try a plugin for firefox that makes it more keyboard oriented, although that would require messing around with POST requests, possibly.
you can couple it with actkbd daemon that will launch xdotool with specific parameters on various keypresses.
Possible, but really hacky. Assuming your application does not support shortcut reassignments (which a lot do, check your application settings first) create a script that uses xdotool to press the application shortcuts for saving followed by the ones for quitting. Then register a global shortcut with your window manager (if it supports this) to launch your script.
Not sure if this other tool helps, but it helps me on my project that has the MQTT I just suggested.
It is called xdotool and it fake keyboard and mouse actions.
There are numerous ways to do this. The Expect solution offered by someone else is elegant.
A simple way to do this via xdotool would be as follows:
stty -echo && xdotool type "This gets typed without enter being pressed..." && stty echo
--overrideredirect value
> Set window's override_redirect value. This value is a hint to the window manager for whether or not it should be managed. If the redirect value is 0, then the window manager will draw borders and treat this window normally. If the value is 1, the window manager will ignore this window.
Taken from here using xdotool
, but you could use wmutils
, or maybe even the very WM you're using...
I don't know about recording the input from X, but for automated mouse/keyboard input, I use xdotool.
If you put it in a script with calls to sleep
sprinkled in for timing (add to taste), you can write a script to automate pretty much any task.
I know you said "Windows tablet", but I'm just gonna leave this here for Linux/OSX(are there even OSX tablets or are they all iOS?) users pondering about the same thing. I don't think Android uses X display server so I don't think it'll work there.
Just make a shortcut on your desktop/taskbar/whatever and link it to the Firefox example, except pressing whatever key you need(space?) and with Wine as the program.
Took me a while to find a solution:
Get xdotool here: http://www.semicomplete.com/projects/xdotool/
Then create keyboard shortcuts: F5 = xdotool key XF86MonBrightnessDown F6 = xdotool key XF86MonBrightnessUp
This not only makes the keys work as expected, but the brightness up and down popovers happen also.
start 'xwininfo', click on your Scratch window. Then look at the xwininfo console output for the Window name. Use that name with 'xdotool search', like in the example. So maybe like this:
WID=xdotool search "Scratch"
xdotool windowactivate --sync $WID
I'm a little bit confused on what you are trying to accomplish.
If you mean what I think you mean I wouldn't use python.
If you are using a linux system there are tools like xdotool which are suited for automating mouse and keyboard inputs. You could easily write a shell script which simulates random keyboard inputs and select windows randomly
Xdotool can send keyboard clicks to specific windows, just use the "-window" switch. You can find examples on the project site, and I'd recommend reading the man page.
This is not bash, but rather an api of sorts. This will not help you per-say. What you may want to look into is a few tools that can do what you wish.
http://tomas.styblo.name/wmctrl/
http://www.semicomplete.com/projects/xdotool/
for example: xdotool windowminimize $(xdotool getactivewindow)
But reading over again What you said.. I'm still not quite sure what you want. Do you want to KILL it, or merely minimize?
If you wan to kill an app on the fly, may i suggest xkill, you can hotkey this and kill anything on the fly. May I ask what the app in question is?
There seems to be a patch for xdotool allowing it to close windows, but as far as I can see it has yet to actually make it in to a release.
xdotool search --class <class name goes here> windowminimize %@
minimises all windows belonging to a program. With the patch, there should be a windowclose or windowdelete action that works similarly.
EDIT: I applied the patch (it will give errors when patching xdo.c; that's OK, because it tries to fix a typo which has now been fixed in the release version too), then tested this with Skype (which also goes to the tray if the window is closed). It does not work as expected, because the tray icon is a Skype window, so it closes that too.
xdotool search --name <window title goes here> windowdelete %@
works much better, and for Skype, does exactly what one would expect.
EDIT 2: You could probably do it without the patch, by generating keystrokes, to activate either your WM's "close window" shortcut, or the application's minimise to try shortcut, if it has one. Perhaps adapt the Firefox example.
Exactly. I used xdotool since I was on linux, but it works the same.
My automation script worked like this:
For speed I stuck the saves folder on a RAM disk so I was never actually saving these levels.
It worked pretty well, except my exit-level automation got completely confused if the player died while the level was loading. That actually happened a few times! I fell in lava once and spawned inside solid rock half a dozen times.
It doesn't look like wmctrl supports that, but I just glanced through this and it looks like xdotool supports using percentages instead of fixed numbers (search for "windowsize" on that page).
I recently came across this http://www.semicomplete.com/projects/xdotool/ and it's supplanted my rare use of wmctrl so it may be of interest to you. (found here https://github.com/patrickhaller/no-wm)
To contribute, I'm using XFCE but only until I replace all my badly behaving programs and switch to dwm.