On Sun, Sep 15, 2002 at 09:18:14AM -0400, Randy Kramer wrote: > Since I started making a transition to Linux, I've been looking for a > keyboard macro program. By that I mean a program that will intercept > the keystrokes from my keyboard and send a string of keycodes to an > arbitrary program. For console I don't know, but many x terminal emulators definitely can do it. > (In dos/Windows (I'm not 100% certain I actually ever used a keyboard > macro program in Windows) I could set up certain keystroke combinations > to send long strings to any program. Maybe <alt><shift><F10> would > send my sig, or a salutation, like "Dear Sir", or whatever.) For things you mention, the you need to do it in editor only. Both vim and emacs allow you to bind (almost) any key combination (including multi-char) to any command or macro. So you want to set these in the editor (sure do look for mail client (and similar things) that use external editor so you can pick one that can do what you want). > Haven't found anything so far in Linux. > > I've looked at and/or tried: > > loadkeys: I can use loadkeys to send a different keycode, but haven't > found a way (and don't think there is a way) to send a string of > keycodes in response to one keystroke. This one is lowest level console stuff. It can't do that. But at first glance to man page, screen is able to do arbitrary input string translations. > expect: From what I've read and tried so far I think: > * Programs like kwrite (just one example) don't accept input from > stdin, or send screen output to stdout, so I don't think something like > expect, which, IIUC, looks at things on stdout and sends things to > stdin, can have any effect on kwrite No, you have to make difference between terminal-based apps and X apps. Mapping keyboard for them is a LOT different matter. > * Assuming kwrite could accept input from stdin, I'd really want > expect to be sort of a filter on stdin -- look at things coming in on > stdin, and replace them with something else if it triggers one of the > "expect rules" that I would set up kwrite is an X app. It recieves input and sends output via the X server connection. There is an X input extension, that allows to do almost arbitrary transformations on input. So you might even be able to do the mapping using xkb or xmodmap maps. However I don't understand these too deeply, so I am not sure. > The author of klipper promised to do somethings in the klipper with kde > 3.0 (and he might have) but even so, those things will work primarily > with kde applications. I bet you don't want the mapping to be universal anyway. You want a key to add your signature to work only in your editor and only when editing mail. And so on. The more advanced applications (I don't mean KDE - it's applications usaly lack powerfull configuration features of things like vim or emacs). > So, I'd like to take a semi-serious look at writing my own program. > (By semi-serious, I mean that I probably don't have the programming > skills at this time to actually write the program, but I'd like to > attempt to figure out a workable approach and what would be involved.) I really thing that you can do what you want with screen on console and xterms, with xterms themselves in xterms and it may be possible with X input extension in X (though I am not sure if it's possible with builtin features - but you can have a program to implement it) > In the dos world, one way of writing a program like this is to > intercept (hook) the keyboard interrupt, look at the input from the > keyboard, and if appropriate, substitute some different input. > > Anybody know: > > * If a similar approach can be followed in Linux? No. You must intercept it's stdin or X events (both is possible). > * Where to learn more about how Linux handles this type of thing and > how I could hook the interrupt in Linux? (Must I dig into the Linux > kernel? Into the whole Linux kernel?) You can't. It's a really wrong idea. It belongs to user space and is possible in user space. > * Pointers to resources (books, articles, appropriate mail lists, > etc.)? For console - i really thing screen can do it - look at it's man page. For X, AFAIK there are pointers to X specifications on www.x.org. > * Other suggestions? Try to do it in each application using features it provides. You seldom find a key binding useful in many contexts. You can't expect KDE to be much use here. Learn vim or emacs and use that. ------------------------------------------------------------------------------- Jan 'Bulb' Hudec <bulb@ucw.cz> -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/