2

I simply want to do something like this Home+Shift(down)+End+Shift(up) (up and down represent Shift key being held). This makes it possible to select the whole line which the cursor is on (useful when copying, deleting etc).

With AHK, that was done by using:

Send {Home}
Send {blind}+{END}

But now I'm on Linux, I have no idea how to do something as simple as that.

keyboard.send_keys("<home>+<shift>+<end>")

simply does not work. Any help is appreciated.

Fritjof Larsson
  • 103
  • 1
  • 4
  • 5

2 Answers2

2

Following do something like Home+Shift(down)+End+Shift(up)

# if you want select select a line:

keyboard.send_keys('<home>')
keyboard.send_keys("<shift>+<end>")

# keyboard.send_keys('<home><shift>+<end>")  # <= this gives an error
# keyboard.send_keys('<home>+<shift>+<end>")  # <= this gives an error and has a different meaning.

# if you want select the word under your cursor you could do the following:
def select_text(keyboard, len_clipboardBackup = 0):  #  0 if dont know the clipboard/text but try select anyway
    keyboard.release_key('<ctrl>')
    if not len_clipboardBackup or len_clipboardBackup > 100:
        keyboard.send_keys('<ctrl>+<shift>+<left>')  # faster but not as exact. forgets special letters.
    else:
        for i in range(0, len_clipboardBackup):
            keyboard.send_keys('<shift>+<left>')
SL5net
  • 1,446
  • 3
  • 15
  • 32
  • I just tried `keyboard.send_keys("+")`. It worked fine in kate, but did something weird on this page in my browser. It did not produce any errors in either case - once I used matching double quotes. – Joe Oct 11 '20 at 20:41
1

What kind of application are you trying to control? You might want to use xdotool as described here: https://github.com/autokey/autokey/wiki/Known-limitations

Rado
  • 56
  • 3
  • Firefox, Thunderbird, Kate (KDE text editor) along with any program where I have to input more than one line. I know that many text editors have a shortcut for selecting the whole line, but it would be more convenient to me if there is a global one (AHK nostalgia). Thanks for your suggestion, I'll try xdotool when I'm free. – Fritjof Larsson Mar 04 '20 at 17:47