Hot answers tagged

96

I know this was already answered, but the answer doesn't explain what's going on. Characters like Ctrl+L are handled by the application. In the case of entering input into the shell, like bash, it clears the screen. Some applications, like emacs, use it to redraw the screen and/or recenter the cursor. Characters like Ctrl+U at a password prompt are ...


54

You just have to type ctrl+u. Enjoy =)


32

Those 'special' headphones or earphones which can be used on specialized devices to control media players, volume and mute usually have FOUR connections on the plug, versus the typical THREE a normal headphone output jack has. The usual three are Left Channel, Right Channel and Ground (common), while the fourth is often set up as a multi-value resistance, ...


25

Ctrl+4 sends ^\ Terminals send characters (or more precisely bytes), not keys. When a key that represents a printable character is pressed, the terminal sends that character to the application. Most function keys are encoded as escape sequences: sequences of characters that start with the character number 27. Some keychords of the form Ctrl+character, and a ...


23

#!/bin/bash stty -echo IFS= read -p 'Enter password: ' -r password stty echo printf '\nPassword entered: %s\n' "$password" stty -echo turns off the terminal echo, which is the display you're talking about; IFS= is necessary to preserve whitespace in the password; read -r turns off backslash interpretation. In bash you can also use read -s, but this ...


20

xinput test can report all keyboard events to the X server. On a GNU system: xinput list | grep -Po 'id=\K\d+(?=.*slave\s*keyboard)' | xargs -P0 -n1 xinput test If you want to get key names from the key codes, you could post-process that output with: awk 'BEGIN{while (("xmodmap -pke" | getline) > 0) k[$2]=$4} {print $0 "[" k[$NF] "]"}' Add ...


19

SSH might be reading from standard input, eating up your actionlist. Try to redirect ssh's standard input to /dev/null : ssh $REMOTE_HOST zfs snapshot -r ${RMT_FILESYSTEM}@${MARKER} </dev/null As a general rule, when running commands that may interfere with standard input under a while read-style loop, i like to wrap the whole loop body into braces: ...


18

Try the following command : xdotool getmouselocation 2>&1 | sed -rn '${s/x:([0-9]+) y:([0-9]+) .*/\1 \2/p}' See http://www.semicomplete.com/projects/xdotool/


17

Assuming your GUI is X-based (as almost all UNIX GUIs are), use xinput. First, list your devices: $ xinput --list ⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ Windows mouse id=6 [slave pointer (2)] ⎣ Virtual ...


17

Use the uinput driver. I don't think there's a utility for that; you're going to have to write or adapt a bit of C code. In a nutshell: #include <fcntl.h> #include <ioctl.h> #include <unistd.h> #include <linux/input.h> #include <linux/uinput.h> /* Set up a fake keyboard device */ fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK); ...


16

If you're writing a real-world program that uses the mouse in Linux, you're most likely writing an X application, and in that case you should ask the X server for mouse events. Qt, GTK, and libsdl are some popular C libraries that provide functions for accessing mouse, keyboard, graphics, timers, and other features needed to write GUI programs. Ncurses is ...


16

GUI programs don't read from their standard input, they get their input from the X server. There are tools to inject a keystroke to a window. xdotool is fairly common and convenient. You'll need to find the window ID that you want to send the keystroke to. You can do that with xdotool. xdotool search --class Chrome returns the list of window IDs of all the ...


14

If you are operating at the X level (as in Gilles' question), then use xdotool like so: xdotool key KEYSTROKE_SPECIFIER Where KEYSTROKE_SPECIFIER can be something like "a" or "F2" or "control+j" EDIT: I missed your response to Gilles' question, sorry. I'll leave this response here as a solution for the X-case.


14

There are numerous issues with that script, but the one thats causing your specific issue is because you're reading from a pipe (the output of ls). 1. Don't parse ls Use this instead for currentSong in *; do ... done Aside from the numerous reasons you shouldnt parse ls, the issue you're seeing is because STDIN is connected to the output of ls. So ...


14

wc will tell you what file it's working on if it's able. With the first one with the pipe it's reading from stdin, not a file, so does not report a filename. The second one, however, you're using process substitution which presents the output of the command as a file, which wc reports. It reports on the file descriptor it was given from which to read.


11

You may find useful xinput list and xinput test <device>. For example, $ xinput list ⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ SynPS/2 Synaptics TouchPad id=11 [slave pointer (2)] ⎣ Virtual core keyboard id=3 ...


10

One more option is xinput. For instance, xinput test 8 would write motion a[0]=496 a[1]=830 motion a[0]=496 a[1]=829 motion a[0]=496 a[1]=832 motion a[0]=496 a[1]=834 upon mouse movement, where "8" is my mouse device number. Use xinput --list to find out the number of your mouse among devices.


9

Use a here string ./program_name <<< 'my input string' or a here document (longer, but standard): ./program_name <<EOF my input string EOF


8

If I understand correctly, you're running the script directly from a GUI environment, not from inside a terminal. The terminal is what provides the script a way to receive input. If you run the script from the GUI via a menu entry or a keyboard shortcut, the script's input is connected to nothing (this nothing is called /dev/null), so when you ask to read a ...


8

xinput --set-int-prop is deprecated. You should use --set-prop instead. Also, xinput --enable [device] and xinput --disable [device] can be used to enable and disable devices respectively. Here is a shell script I use to enable, disable, and toggle my laptop's touchpad: #!/bin/bash # Enables, disables, or toggles device device='AlpsPS/2 ALPS GlidePoint' ...


7

If you're NOT working with X programs with windows that can be sent keys, you are probably looking for expect, a handy and very configurable program for running other interactive shell programs as if a user were controlling the terminal. You can setup programatic responses to respond to various output with different inputs.


7

The command vipe in the package moreutils allows you to launch $EDITOR in the middle of a pipeline. You can get the desired behaviour like so: $ </dev/null vipe |sort -nr | uniq -c


7

That's typically what expect was written for: expect -c 'spawn -noecho vi; send "iHello World!\r\33"; interact' While expect was written for TCL in days prior to perl or python being popular, now similar modules for perl or python are also available. Another option is to use the TIOCTSI ioctl to your tty device to insert characters in the input queue of ...


6

As Michael suggests, the window manager is not responsible for managing the input method. First you will need to choose an input method, of which IBus, SCIM and uim appear to be the most popular. Next, you need to make sure it is started when X is launched. You've mentioned you are using a lightweight WM, therefore you'll likely want to add it to an X init ...


6

I and friends of mine made some good experiences with the tablets from Wacom. The Bamboo series contains different tablets in different pricing categories. My Bamboo for example is connected via USB, the pen as 2 Buttons, the tablet is only sensitive to the pen, has some more buttons and works with my linux out of the box. So this should satisfy your ...


6

I wrote some Python code that does that. You can find it in my open source project. http://code.google.com/p/pycopia/source/browse/trunk/core/pycopia/OS/Linux/event.py If you run that module as a script as root you can see a demo in action. This basic functionality was extended for another project, powerdroid, that provides more concrete implementation ...


6

Try doing this : $ read -r -p 'Please enter a string >>> ' var $ printf '%q\n' "$var" \*\*\*\<\>\<\>\<\|\|\&\&\*\&\$PATH


6

Change the first line in 50-synaptics.conf to Section "InputClass" InputDevice was used to define rules and options for a specific device and I'm not sure if it's still supported. InputClass is a newer section that allows for matching a number of connected devices depending on various match rules. Because you have the line MatchIsTouchpad you should ...


6

In addition to Gilles answer let me add, that you can always input non-printable characters in bash with Ctrl-v+key (Ctrl-v+Ctrl+4 in this case) and check the character code with $ printf '^\' | od -An -tu # input ^\ as C-v C-4 28 you get the decimal code of the character, which as you may check in man ascii corresponds to file separator (FS).


6

One advantage to allowing the shell to do the open() like: utility <in >out as opposed to allowing the named utility to do the open() like: utility in >out ...is that the file-descriptor is secured before the named utility is called, or else if there is an error encountered during the open(), the utility is never called at all. This is the ...



Only top voted, non community-wiki answers of a minimum length are eligible