Why doesn't shift insert work in an xterm in Cygwin/X? - cygwin

shift insert works in mintty, but when I launch X with
/usr/bin/startxwin -- -xkblayout "us" -xkbmodel "pc105" -xkbvariant "altgr-weur" -xkboptions "altwin:meta-win,compose:rctrl,ctrl:nocaps" -listen tcp&
xterm only shows 2~ when pressing shift insert. How do I make this work correctly? Do I have to configure something special in .inputrc or .XResources to make this work? I never changed any of the cygwin defaults on this.
shift insert works as intended in emacs under X.

Try this :
xrdb -merge << EOF
XTerm*VT100.translations: #override\n\
!Shift<Key>Insert : insert-selection(CLIPBOARD,PRIMARY)
EOF

I used xev to check the keycode. The windows On-Screen Keyboard returns 106 when I do a shift insert while the physical keyboard returns 90. Keycode 106 = Insert while keycode 90 = KP_Insert.
I only need a xmodmap -e 'keycode 90 = Insert" on my machine :)

Related

Midnight Commander (mc) normal "+" and "-" keys working as those on numpad

When I press normal "+" or "-" on keyboard, they work as I'd press those on numpad - mc is popping the dialog for selecting/deselecting files. So its impossible to type any command that contains "+" or "-" (like eg. "ls -al").
This happens on my laptop (which doesn't have numpad), but also on standard ANSI keyboard connected with USB.
"Learning keys" in mc doesn't seem to help.
This is the same for Debian 9 and Debian testing (10).
Any idea why this is not working correctly?
My mc version shows "3:4.8.21-1".
For me + and - open these dialogs only when the command line is empty. After I enter some non-special characters + and - are added to the command line.
To enter any special character at the command line press Ctrl+q: Ctrl+q + (or -).

Sending Ctrl-L via dbus to terminal emulator

One can send text via dbus to the terminal emulator konsole as followed:
qdbus org.kde.konsole /Sessions/1 sendText "hello"
However I want to remotely clear the screen of the specified terminal window.
So I tried:
qdbus org.kde.konsole /Sessions/1 runCommand "clear"
Does partly what I want. Only problem: The screen doesn't get cleared when there is a process running.
In the terminal emulator, in this case the key combination "Ctrl + L" would do the job.
So I'm trying to send a string with escape characters for this shortcut.
Is this going to work? This, however doesn't do;
qdbus org.kde.konsole /Sessions/1 sendText "\033[2J"
(runCommand neither)
This is working for me:
qdbus org.kde.konsole /Sessions/1 sendText $'\014'
First, to produce a character from its octal code, the syntax "\033" would work in C but not in Bash.
Second, while "ESC [ 2 J" is a VT100 code to Erase Screen, it work for me only if I echo $'\033[2J', and that will not work if a command is running.
Third, Ctrl-L will work if a program is expecting input from a terminal (like irb or python do), but it will not work for a while sleep 1; do echo Still running; done loop.

Use backtick/Grave/Tilde as modifier key

I'm looking for a way to create keyboard shortcuts in Linux using backtick (`) / tilde (~) key and some other key. In an ideal case:
pressing tilde down does nothing
pressing another key while the tilde is pressed down triggers a (customizable) shortcut
when releasing the tilde before/without pressing another key, just send the tilde keystroke.
I have something similar in AutoHotKey for Windows, and i've been searching for a way to recreate this in a (any) Linux environment. I would consider using any GUI if i could get this working, but of course a more "general" solution would be even better.
I think i finally got it!!
I use xmodmap to turn the grave key into the modifier Hyper_L, and XCape to send the grave if the key is released without another key being pressed.
Xcape was intended to open the app menu ("Start menu") when the meta-key ("windows key") is pressed and released without another key, so as an added bonus, it does that too. Meaning you can both use Meta as a modifier, like Meta-F to open the file manager AND use the meta-key seperately to open the whiskers menu.
If all is right, you can open the keyboard settings manager using ~-k, and you can make new shortcuts using the ~-key. Because that's still tiresome and not easily portable between different systems, i've included some shortcuts using xfconf-query, which will probably only work in Xfce.
Here's the basics of my script:
#!/bin/sh
# reset pretty much ALL keyboard settings
setxkbmap
# Free up the mod3 and mod4 flags from all keys it may be associated with:
xmodmap -e "clear mod3"
xmodmap -e "clear mod4"
# Add Hyper_L to the grave key (49)
xmodmap -e "keycode 49 = Hyper_L asciitilde grave asciitilde"
# You need a grave key somewhere else (!) so, bind it to an unused key:
xmodmap -e "keycode 250 = grave"
# Restore Mod4 but without Hyper_L (which was at location 4)
xmodmap -e "add mod4 = Super_L Super_R Super_L"
# Assign the mod3 to Hyper_L:
xmodmap -e "add mod3 = Hyper_L"
dist=100
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>Right -s "xdotool mousemove_relative -- $dist 0" --create -t string
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>Down -s "xdotool mousemove_relative -- 0 $dist" --create -t string
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>Left -s "xdotool mousemove_relative -- -$dist 0" --create -t string
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>Up -s "xdotool mousemove_relative -- 0 -$dist" --create -t string
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>space -s "xdotool click 1" --create -t string
/usr/bin/xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/\<Hyper\>k -s "xfce4-keyboard-settings" --create -t string
# (re)starting xcape to produce a ` after key-up if no other key was pressed
killall xcape
xcape -t5000 -e "#49=grave;Super_L=Control_L|Escape" &
A more extended version of the script, with some more shortcuts can be found here.
I am not sure if it will work out for you but you should check:
xdotool (http://manpages.ubuntu.com/manpages/precise/man1/xdotool.1.html)
zenity (http://manpages.ubuntu.com/manpages/precise/man1/zenity.1.html)
Both these tools let you create some custom actions and shortcuts.
Here is an example of xdotool: https://askubuntu.com/questions/212154/create-a-custom-shortcut-that-types-clipboard-contents
Hope it helps and good luck :)
Bruno
After switching to Ubuntu on another machine, I also wanted to use tilde as a modifier key the way I use it in my AHK scripts.
I did quite some research on different tools for ex. xdotool, xev, autotools, xbindkeys and so on and finally found a solution to that. Here are the steps.
Install Autokey, python, python evded module, xte(sudo apt-get install xautomation).
Read a little about Autokey and how it launches python scripts or create hotstrings. In Autokey, we can set a hotkey to call a python script. So you can assign the python script down below to your tilde key or for that matter whatever custom hotkey you plan to create.
Here is the required custom functionality(thought not yet completely ported to linux, I have it scripted in autohotkey and just love it. It keeps the hand glued to keyboard ;))
Tilde + Up arrow: Move mouse pointer upwards by 100 positions
Tilde + Down arrow: Move mouse pointer downwards by 100 positions
Tilde + Right arrow: Move mouse pointer to right by 100 positions
Tilde + Left arrow: Move mouse pointer to left by 100 positions
Tilde + Enter: Left Mouse click (not present in the python script)
Tilde + Alt + Enter: Right Mouse Click
I use the tilde (KEY_GRAVE) as my modifier key. When this key is pressed, Autokey launches the python script. The scripts runs a loop until the tilde key is released. In the loop, the script keeps on detecting the keyboard inputs. On a UP arrow key(KEY_UP) press, the script sends a command to move a mouse by relative position (0, -100) utilizing 'xte' and so on.
from evdev import InputDevice, categorize, ecodes
from select import select
dev = InputDevice('/dev/input/event4')
releasekey = False
while releasekey==False:
r,w,x = select([dev], [], [])
for event in dev.read():
if event.type == ecodes.EV_KEY:
#system.exec_command("xte 'mousermove 0 3'", False)
#break
if event.code == ecodes.KEY_UP:
if event.value == 1:
system.exec_command("xte 'mousermove 0 -100'", False)
if event.code == ecodes.KEY_DOWN:
if event.value == 1:
system.exec_command("xte 'mousermove 0 100'", False)
if event.code == ecodes.KEY_RIGHT:
if event.value == 1:
system.exec_command("xte 'mousermove 100 0'", False)
if event.code == ecodes.KEY_LEFT:
if event.value == 1:
system.exec_command("xte 'mousermove -100 0'", False)
if event.code == ecodes.KEY_GRAVE:
if event.value == 0:
releasekey = True
break
You have to adjust the dev = InputDevice('/dev/input/event4') line to assign the correct name of your keyboard. In my case, event4 is my keyboard. Yours might be different. You can check out the handy tutorial "Reading Events" on python-evdev. That code actually outputs the name of your keyboard listed under /dev/input. Actually, my script is an extention to that tutorial script.
The only problem is that the python script must be started as a root user otherwise the keyboard input device can not be accessed. You can overcome this by creating a udev rule file which changes the permission of the device to make it available for reading writing eg. create a rule file and add this line
KERNEL=='event4', MODE="0660" and load the rule . At the end you must add yourself in the GROUP which have read/write permission for the device. The information regarding file permission can be found using ls -la in the /dev/input folder.
I hope it works for you. In it doesn´t work at first go, then get a cup of coffee and fight on till it works ;)

Keyboard script for pressing a key

I am looking for a simple linux program that will allow my keyboard to press a key for few seconds and then another one for few other seconds.
Thank you.
Check out xdotool, which lets you simulate keyboard input.
sudo apt-get install xdotool
#!/bin/bash
for i in `seq 0 9`;
do
xdotool key $i
done
UPDATE
To simulate a pressing a key for six seconds in Bash, then simulate pressing a different one for a further six seconds will be painful.
Therefore, I would use Ruby (you might have to install this from the repositories).
ruby -e 't = Time.new.to_i; key = "a"; while true do `xdotool key #{key}`; key = "b" if Time.new.to_i > t + 6; break if Time.new.to_i > t + 12; end'
If you run this from the command line it will simulate pressing key "a" for six seconds, after which it'll simulate a pressing key "b" for a further six.

Can't close a scpi(telnet) session with echo "^]" when I use it in a script

The use of echo-e "\ 029" does not work either.
But if use strg + alt gr + ] directly in a terminal session -> it works.
I have to ask my question more concretely:
I connect an RF generator (AGILENT) via Telnet/SCPI.
If I do this manual on terminal and press at the end of the session CTRL + ALT GR +] for '^]' then close the scpi session properly and I can type quit to close the telnet session properly.
There is no error message on the display of the RF generator. So it should be.
If I do this via script the SCPI session seems not to recognize the break signal condition '^]' and will be forced to close after the end of the script (telnet and scpi). -> Message: "Disconnected by foreign host". Unfortunately, I get error messages on the display of the RF generator -> "invalid header", etc.
After successful connection appears:
Connected to 192,168.10.66
Escape Character is ‘^]’ -> This is the point at issue. Manual entry in the terminal works correctly, script does not work.
My script looks something like this:
function getIDNMessage()
{
(
echo open $1 $2
sleep 1
echo "*IDN?"
sleep 1
echo –e "\029" # or echo “^]” does not work well
sleep 1
echo "quit\r"
sleep 1
) | telnet > scpi_telnet.log 2>&1
}
getIDNMessage 192.168.10.66 7777
On Linux it's actually:
CTRL + ] then ENTER
Finally type in the quit command.
^]
telnet> quit
Connection closed.
[fred#localhost ~]$
To quit telnet on redhat:
type "CTRL+5" and then type "quit"
To Close Session Use below command
Ctrl + ]
telnet> quit
it works perfect in REHL and CentOS.
The ^] means ctrl + right bracket. As strange as that is, it works. You'll be taken to the telnet prompt, where you can type quit.
On international keyboards the ] character is often not a single key, and needs to be replaced with some other key. The correct key is typically the key to the right of P or the next key after that.
Here's a list based on comments below:
Finnish, Swedish, Norwegian, Danish: ctrl + å
French: ctrl + 6
German: ctrl + ü
Swiss: ctrl + ¨
Hungarian: ctrl + 5
Portuguese: ctrl + ´
Dutch, Belgian: ctrl + $
Canadian French: ctrl + ç
It must be so. Because ^] printed in the terminal on the server means for the client side nothing. The client must catch this symbol before it will be transmitted to server and of course you can't just write it to terminal in te program running on the server.
So you need to interrupt session in other way. There are many methods.
If you are inside the running program, you can simple terminate it (exit in shell or sys.exit() in python or exit() in many other languages).
If you can't control program flow you can close terminal by killing the process that is owner of the terminal. You need to find the process and then use kill ... (PID of the process instead of ...).
If you want to close the client from client side, you need to do the same (kill ...) but on the client side.
On my danish keyboard it was not Ctrl + å - but instead the key to the right side of å (which has a hat, a tilde and a umlaut)
On MacOS with Turkish keyboard try:
Ctrl + Option + ü
Then,
> quit
Ctrl + ] This will show as ^] and then
telnet> q q is for quit
When opening a connection you can specify the escape character. e.g.
[root#localhost ~]# telnet -e % localhost
Telnet escape character is '%'.
Trying 127.0.0.1...
Connected to localhost.
Escape character is '%'.
>%
telnet> quit
Connection closed.
[root#localhost ~]#
In here, I just used the % symbol to close the session, for that I had to tell telnet to use it as an escape character. I find this useful since the character ^] could be different on different keyboard layouts.
IF you are here in 2022 and using Mac OS or AWS Linux and using Apple Magic keyboard
^]
telnet> quit
Connection closed.
Where ^] is "Control + ]"

Resources