linuxkeyboard-shortcutsautokey

Emulating Home+Shift+End with Autokey


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.


Solution

  • 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>')