In a bash script, how can I replace
Code: Select all
xdotool key Return
I'd also need a replacement for
Code: Select all
xdotool key g
Many thanks in advance for any leads.
Code: Select all
xdotool key Return
Code: Select all
xdotool key g
Code: Select all
!rox /root/.config
Code: Select all
xdotool key Return
Code: Select all
!rox /root/.config ; xdotool key Return
Code: Select all
SHELL=/path/to/your/script.sh less /path/to/file_to_view
Code: Select all
#!/bin/sh
less_window_id()
{
# write some code that determines the X-window id associated with
# the less window that started this script
echo $less_window_id
}
# invoke less' bang command arguments
"$@" &
sleep 0.5 # half a second
xdotool --window $(less_window_id) key Return
# End of script
You can't.musher0 wrote:In a bash script, how can I replacewith an internal bash command?Code: Select all
xdotool key Return
Did you really manage to send the keystroke back after invoking the shell from less with the "!" option? How?musher0 wrote:I'd like to send the Enter keystroke back to less so I don't have to press
the Return key every time.
xdotool will do it with this commandCode: Select all
xdotool key Return
This won't work as xdotool still runs within the shell opened by less. The Return key is sent ot ROX, not to less. Less will wait for the shell to exit and then display its "Press RETURN" prompt. At this point all the code from the "!" shell is dead and there is no way for any post mortem action to communicate with less. I would be glad if someone can prove me wrong because this would open new opportunities.Peterm321 wrote:Code: Select all
!rox /root/.config ; xdotool key Return
Code: Select all
!sh -c "xemeraldia";xdotool key Return
Code: Select all
!rox /root/.config ; xdotool key Return
Code: Select all
rox /usr/share/applications/leafpad.desktop
Code: Select all
rox /root/.config # &
Doesn't work here, but it works when Imusher0 wrote:BTW, Peterm321's line:works like a charm.Code: Select all
!rox /root/.config ; xdotool key Return
Probably because rox "releases" the calling script as soon as it's shown
the directory.
Code: Select all
!xdotool key Return; rox /root/.config
Code: Select all
// Send a fake keystroke event to an X window.
// by Adam Pierce - [url]http://www.doctort.org/adam/nerd-notes/x11-fake-keypress-event.html[/url]
// This is public domain software. It is free to use by anyone for any purpose.
#include <X11/Xlib.h>
#include <X11/keysym.h>
// The key code to be sent.
// A full list of available codes can be found in /usr/include/X11/keysymdef.h
#define KEYCODE XK_Down
// Function to create a keyboard event
XKeyEvent createKeyEvent(Display *display, Window &win,
Window &winRoot, bool press,
int keycode, int modifiers)
{
XKeyEvent event;
event.display = display;
event.window = win;
event.root = winRoot;
event.subwindow = None;
event.time = CurrentTime;
event.x = 1;
event.y = 1;
event.x_root = 1;
event.y_root = 1;
event.same_screen = True;
event.keycode = XKeysymToKeycode(display, keycode);
event.state = modifiers;
if(press)
event.type = KeyPress;
else
event.type = KeyRelease;
return event;
}
main()
{
// Obtain the X11 display.
Display *display = XOpenDisplay(0);
if(display == NULL)
return -1;
// Get the root window for the current display.
Window winRoot = XDefaultRootWindow(display);
// Find the window which has the current keyboard focus.
Window winFocus;
int revert;
XGetInputFocus(display, &winFocus, &revert);
// Send a fake key press event to the window.
XKeyEvent event = createKeyEvent(display, winFocus, winRoot, true, KEYCODE, 0);
XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);
// Send a fake key release event to the window.
event = createKeyEvent(display, winFocus, winRoot, false, KEYCODE, 0);
XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);
// Done.
XCloseDisplay(display);
return 0;
}