sendkeys icon indicating copy to clipboard operation
sendkeys copied to clipboard

xsendkey 'A' prints 'a'

Open spaceone opened this issue 9 years ago • 7 comments

Hello ;) You saved my life. But my biggest problem now is to be able to send uppercase chars. How to?

./xsendkey 'A' sends 'a'.

spaceone avatar Dec 03 '15 10:12 spaceone

Ahh I got it.... 'Shift+A'. Maybe filtering the input and add this automatically? Or write more examples into the README. Is it possible to print whole words using this one process?

spaceone avatar Dec 03 '15 10:12 spaceone

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys 
from subprocess import call

for char in sys.argv[1]:
    if char.isupper():
        char = 'Shift+%s' % (char,)
    call(['xsendkey', char])

spaceone avatar Dec 03 '15 10:12 spaceone

How to send those character independent of the keyboard layout? *,-.:;<>?@[\]^_{|}~'`

spaceone avatar Dec 03 '15 11:12 spaceone

http://linux.die.net/man/3/xstringtokeysym tells "Standard KeySym names are obtained from <X11/keysymdef.h> by removing the XK_ prefix from each name.". The header file is located at: /usr/include/X11/keysymdef.h

xsendkey Shift+asterisk prints a * therefore. I don't understand why Shift is needed.

spaceone avatar Dec 04 '15 02:12 spaceone

Hi spaceone. Thanks for this.

Part of the problem is that the input is filtered for uppercase characters, but only in sendkeys.sh. So, sendkeys.sh 'Terminal' 'H', should work, but sendkey.sh 'Terminal' 'H' and calling xsendkey 'H' directly don't work. The filtering could be moved to solve this, but as you point out, there is also a more fundamental problem with handling different keyboard layouts.

I see you have created a fork, which looks promising. Let me know if you'd like me to merge something.

kyoto avatar Dec 22 '15 01:12 kyoto

Hi :) So far I created a forked version which I call 'xsendword' which is able to evaluate multiple arguments. Maybe I will find a solution to the problem otherwise I will make a static mapping: https://github.com/spaceone/sendkeys/blob/master/xsendword.c

spaceone avatar Dec 22 '15 09:12 spaceone

http://linux.die.net/man/3/xstringtokeysym tells "Standard KeySym names are obtained from <X11/keysymdef.h> by removing the XK_ prefix from each name.". The header file is located at: /usr/include/X11/keysymdef.h

xsendkey Shift+asterisk prints a * therefore. I don't understand why Shift is needed.

Shift is still needed because "asterisk" is a key "named", which has 3 characters that works with at least 2 modifiers (shift+altgr). That's why the asterisk needs to press Shift to produce an asterisk. If "asterisk" did not have such name, you'll need to know the keycode which represents that key.

So, if you send "asterisk", it will should produce "+", then I will call that key "sum" or "+" instead of "asterisk".

erm3nda avatar Apr 24 '23 09:04 erm3nda