FunKeyMonkey


how can you output special characters, like n-tilde, or other unicode vars, @bzar?

[edit]
is there a better way than doing this:
Code:
out->send(EV_KEY, KEY_LEFTSHIFT, 1);
out->send(EV_KEY, KEY_LEFTCTRL, 1);
out->send(EV_KEY, KEY_U, 1);
out->send(EV_KEY, KEY_U, 0);
out->send(EV_KEY, KEY_LEFTSHIFT, 0);
out->send(EV_KEY, KEY_LEFTCTRL, 0);
out->send(EV_KEY, KEY_5, 1);
out->send(EV_KEY, KEY_5, 0);
out->send(EV_KEY, KEY_C, 1);
out->send(EV_KEY, KEY_C, 0);
out->send(EV_KEY, KEY_ENTER, 1);
out->send(EV_KEY, KEY_ENTER, 0);

5C will give back slash (\).... not very exciting, but that kind of idea.
 
Last edited:
Hmm, guess that depends on the keyboard interpreting end. Since funkeymonkey works at the keyboard level, it doesn't have a concept of characters as much as events. Since there's no specific way for any keyboard to communicate for example "ñ", it's always interpreted from other events, like the ctrl-shift combinations you used.

Maybe you could make a xmodmap or similar that maps some rarely used events or event combinations to the desired characters? Then it'd be easier to map to.

On the other hand, depending on your use case the way you've done it may be better. Maybe what would make it easier is a function that takes a key event and a varargs of modifiers, then produces a key press/release with those modifiers?

Then you could have something like:
Code:
keypress(KEY_U, KEY_LEFTSHIFT, KEY_LEFTCTRL);
keypress(KEY_5);
keypress(KEY_C);
keypress(KEY_ENTER);

Yeah, the above is kinda obvious and probably not what you meant :). Anyway, if the question was "is there a way to reliably represent characters that don't have their own event types in uinput, and thus funkeymonkey?" the short answer is no.
 
yeah, you're probably right in that i should use an xmodmap... i just thought it would be nice for the virtual terminal to have something at the input level, in case you want to switch consoles (without alt+arrow, e.g.). maybe there's a good fusion of xmodmap and funkeymonkey that i can use...
 
well, since xmodmap doesn't seem to help with setting Ctrl+Backspace to Delete...

@bzar: would you recommend something else? (i will send a pull request with the updates, if you like it.) some questions, though:
1. is it necessary to push back all the keycodes in order to handle them later? why do keycodes that don't appear in that list make their way into the "handle" method anyways? (i see them get called.)
2. why does EV_SYN need to be called (sorry if i've asked before)?

Code:
UinputDevice* out;
void init(char const** argv, unsigned int argc)
{
  menu = 0; // do not start on menu
  std::vector<unsigned int> keycodes;
  for(unsigned int i = KEY_RESERVED; i <= KEY_UNKNOWN; ++i)
    keycodes.push_back(i);
  out = new UinputDevice("/dev/uinput", BUS_USB, "FunKeyCtrlBackDel", 1, 1, 1, {
    { EV_KEY, keycodes }
  });
}

void handle(input_event const& e)
{
  if (e.type != EV_KEY)
  {
    out->send(EV_SYN, 0, 0);
    return;
  }
  static bool left_ctrl_depressed = false;
  //std::cout << "\nEvent! " << e.type << " " << e.code << " " << e.value << " " << std::endl;
  //std::cout << " back is " << KEY_BACKSPACE << "\n";
  if (e.code == KEY_LEFTCTRL)
  {
    left_ctrl_depressed = ((e.value));
  }
  else if (e.code == KEY_BACKSPACE and left_ctrl_depressed)
  {
    out->send(EV_KEY, KEY_DELETE, e.value);
    //std::cout << " DELETE DELETE\n";
    return;
  }
  out->send(e.type, e.code, e.value);
}
 
Sadly, there doesn't seem to be any definitive documentation for using uinput, but below are a couple of links that, combined, should explain both.

Handle reacts to any events from the source device ("real" input device). The keycodes are pushed for any codes that the target device ("virtual" input device) is able to emit.

When enabling EV_KEY events, we need to describe which keycodes are allowed to be sent via the input subsystem.
source

A single hardware event generates multiple input events. Each input event contains the new value of a single data item. A special event type, EV_SYN, is used to separate input events into packets of input data changes occurring at the same moment in time.
source
 
well, i got funkeymonkey to do it now, so why add a weird popup program? funkeymonkey also works in the virtual terminal setting (Ctrl+Alt+F1, F2, etc.), so it's very flexible and not dependent on X.
 
hey, is it possible, for your program to read from local keyboard, and pump the result through USB cable to remote device?
does it work with locking so it can pump copy of clicked key to the desired destination without making list "everything with everything" ("does it have default result?")
I wanna buy USB-USB male-male active cable, and I want to have program which would use it to pump keyboard and mouse events from half of Notebook (one without screeen) to the full PC. If it's possible it could also pump info from other devices. I may have linux on Laptop if it is required, but I wish the device on other side of cable detect it as default keyboard and default mouse (so it can fit on remote windows too).

PS: I know you used ARM and my Notebook would be x86, but it can be recompiled, yeah?
PPS: by the USB cable I mentioned, I mean those which linux detects as to use with netusb driver by default, but I want clean USB transfer
PPPS: I know it's crazy, but I wish the Notebook to be always-on server, and to place it where I would normally put normal Keyboard :)
 
but I want the remote machine to be using windows too.
I need semi-hardware approach. it means Laptop should work as virtual input device which would be working on PC like real one.
I heard there is a lib-usb library to make usb devices to work non standard way etc. could you help me in the topic?
I may write something myself but I am not reallly knowing where to start :(
 
hey, is it possible, for your program to read from local keyboard, and pump the result through USB cable to remote device?
does it work with locking so it can pump copy of clicked key to the desired destination without making list "everything with everything" ("does it have default result?")
I wanna buy USB-USB male-male active cable, and I want to have program which would use it to pump keyboard and mouse events from half of Notebook (one without screeen) to the full PC. If it's possible it could also pump info from other devices. I may have linux on Laptop if it is required, but I wish the device on other side of cable detect it as default keyboard and default mouse (so it can fit on remote windows too).

PS: I know you used ARM and my Notebook would be x86, but it can be recompiled, yeah?
PPS: by the USB cable I mentioned, I mean those which linux detects as to use with netusb driver by default, but I want clean USB transfer
PPPS: I know it's crazy, but I wish the Notebook to be always-on server, and to place it where I would normally put normal Keyboard :)
Are you wanting to control Windows or Linux? If Linux I recommend x2x
 
@bzar would hot plug functionality be too difficult to implement? i.e. automatically grab events from plugged-in usb keyboards or controllers, without needing to start funkeymonkey yourself.

also, possibly not a bug but a feature: if you ctrl+Z out of the program using a grabbed input, you'll "lock up" your computer (by not being able to use that input). that's when you have to go get a usb keyboard if you don't want to do a reboot (or visual keyboard pkill funkeymonkey??). i suppose i should be using the -d daemonize flag?
 
@ible, not sure. I'd have to look into it.

Supporting freezing would require releasing the grabbed inputs and reconnecting them on resume, which I'm not sure is as simple as it may sound. If you want to run funkeymonkey in the background, you correctly assumed -d flag is the way to go.
 
Back
Top