Announcement

Collapse
No announcement yet.

Trying to use xbindkeys

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Trying to use xbindkeys

    EDIT: It should be ``Trying to use xbindkeys", sorry.

    Hello everyone,

    I switched from windows 10 to Kubuntu 16.04 quite recently. I really like this new operating system, but there are a few things which I found comfortable on windows that I'm missing.

    One is the possibility of doing a backslash with the commands Ctrl + Alt + less, which was the default way on my Swiss keyboard. Now each time that I need to do a backslash I need to press AltGr + less, which I find much less comfortable since I need to look each time at my keyboard when I do this (with the other way I don't since I feel the edge of the keyboard). I use latex extensively so it really bothers me.

    With the help of someone who was more used to Linux I tried to find the same keyboard layout that I used to use on windows (Layaout: ``German (Switzerland)", variant: ``French (Switzerland)"). For the people who are a bit curious, Switzerland has several official languages, the main ones being (by decreasing order of percentage speaking it) German, French, Italian, and I come from the frenchie part. But even with this it's not the same. It looks like even for something as uncommon as this, there are several version. As clearly this keyboard is not the main stream one and that my problem with the backslash comes greatly from me coming from Windows, I gave up the idea of finding a solution to my exact situation, already solved on the net.

    Then I tried to just find a way to force my keyboard to do what I wanted and some little googling hinted at xbindkeys. In particular i tried to apply the solution offered by cheneym here:
    https://unix.stackexchange.com/quest...t-gr-in-ubuntu
    using this page
    https://wiki.archlinux.org/index.php/Xbindkeys
    to help me with the creation of the config file.

    But it didn't work (nothing happens when I press on Ctrl + Alt + less).
    Here is precisely what I did:
    • I copied an example of config file for xbindkeys into my home folder with the command cp /usr/share/doc/xbindkeys/examples/xbindkeysrc ~/.xbindkeysrc

    • I edited the file with vim by adding

      ## Control + Alt + less returns a backslash
      "xvkbd -xsendevent -text '\[backslash]'"
      m:0x4 + c:37 + m:0x8 + c:64 + m:0x0 + c:94
      Control + Control_L + Alt + Alt_L + less
    • I entered

      xbindkeys -f ~/.xbindkeysrc

      in my ~ folder.


    Hence my questions are:
    1) Does anyone know what I did wrong?
    2) Do you see another way to get this done?
    And at another level:
    3) Is this specific forum ``help the new guy" the right place to post it or should I go in another one? Since I'm really a newbie, and that this question comes somehow from my quitting windows and converting to linux, I have the feeling I'm in the right place, but maybe I'm wrong.

    Concerning my machine I have

    Kubuntu release: 16.04
    KDE Plasma Version: 5.5.5
    Qt Version: 5.5.1
    Kernel version: 4.4.0-104-generic
    OS-type 64-bit
    Grub version: Version: 0.97-29ubuntu68
    Other operating system: windows 10
    Laptop: Lenovo T460p

    Have a nice day
    Last edited by Snowhog; Jan 05, 2018, 11:07 AM. Reason: Corrected title

    #2
    You left out Romansh.


    I'm not sure what the "less" key means. The "minus" key and in - or the "less than" key as in < ? Language/keyboard layout issue no doubt.

    So the general method to discover the key combo for xbindkeys is to launch xbindkeys -k in a terminal, this opens a little window on the screen, then you, hit your key combo, and it outputs the key strokes in keycodes for you to copy and use. Your entry has six keycodes and I doubt you're entering six keys so something seems amiss there.

    Other options are Keyboard shortcuts in System Settings and xmodmap (although I think xmodmap is too simple for what you're after). There's also an xbindkeys GUI editor: xbindkeys-config, but I've never tried to use it.

    As far as where to post on the forum - the subforum you select should partially be to target who you want to look at your questions. For something like this, you may get more high-level response in the Coding/Scripting subforum. It's certainly not out of place here, because you are a new user. However, if you would like me to move it - let me know.

    Please Read Me

    Comment


      #3
      (nothing happens when I press on Ctrl + Alt + less)
      Have you looked at xdotool? It's in the repos.

      If you know the current keyboard combination that gives you the key you want, you could reproduce that using xdotool and set up a shortcut (assigning Ctrl + Alt + less as the trigger) to make xdotool carry out the key press sequence you want. See https://askubuntu.com/questions/5916...ode-characters for an example of what you can do with xdotool.
      Kubuntu 20.04

      Comment


        #4
        Thank you to both of you for your answers!

        @oshunluvr Thanks for the answer. Indeed, I didn't mention Romansh, thinking that there was not chance people across the ocean would know about it, since it is really uncommon . And as a matter of fact, I never heard it spoken once in Switzerland. I've been told that it is dying since it's slowly but surely replaced by Swiss-German (Swiss-German is a dialect which has a lot of variants but is slightly different from the ``high German" spoken in Germany).
        Coming back to the main topic, indeed I used this tool from xbindkeys that we obtain by entering xbindkeys -k inside the terminal to find these combinations.
        ``less" on my keyboard is ``<" (on the physical key there is also printed ``>" and ``\ ").
        If I have these 6 (or 5 depending if you count on the first or second line) keys it is because what I believed to be a simple ``Alt" turned out to be ``Alt + Alt_L" (when I used xbindkeys -k to identify it) and ``Control" is in fact ``Contol + Control_L". Here are the terminal ouputs for the three physical keys that I want to combine in order to obtain a backslash
        Ctrl:

        You can use one of the two lines after "NoCommand"
        in $HOME/.xbindkeysrc to bind a key.
        "(Scheme function)"
        m:0x4 + c:37
        Control + Control_L

        Alt:

        You can use one of the two lines after "NoCommand"
        in $HOME/.xbindkeysrc to bind a key.
        "(Scheme function)"
        m:0x8 + c:64
        Alt + Alt_L

        less

        You can use one of the two lines after "NoCommand"
        in $HOME/.xbindkeysrc to bind a key.
        "(Scheme function)"
        m:0x0 + c:94
        less

        I didn't enter Ctrl + Alt + less at once because it looked like it wasn't able to ``capture" the three keys at the same time: I was getting the same result if I was entering Ctrl + Alt + less or only Ctrl + Alt.

        In my .xbindkeysrc file I originally put the two lines for the key combination

        m:0x4 + c:37 + m:0x8 + c:64 + m:0x0 + c:94
        Control + Control_L + Alt + Alt_L + less


        following the link where I had found this solution (i.e. https://unix.stackexchange.com/quest...t-gr-in-ubuntu), but then I tried to include only one line for the key combination, i.e.

        ## Control + Alt + less returns a backslash
        "xvkbd -xsendevent -text '\[backslash]'"
        Control + Control_L + Alt + Alt_L + less


        and I also tried like this

        ## Control + Alt + less returns a backslash
        "xvkbd -xsendevent -text '\[backslash]'"
        Control + Alt + less



        but in both cases it doesn't work.

        I will try again to find the exact keyboard layout of my windows session since you recommend this approach, but it means I have to launch Windows again. I haven't done it since months and I fear the 35'238 updates waiting for me which I will be forced to accept to turn down my computer...

        @chimak111 Thanks for the answer. I looked at the link but I'm not sure to understand how to use xdotool. I tried

        xdotool Control+Alt+less U+005C

        but I obtained the following error message:

        xdotool: Unknown command: Control+Alt+less
        Run 'xdotool help' if you want a command list

        I looked at the possible commands but I don't find Control+Alt+less. How should I proceed?

        Have a nice day!

        Comment


          #5
          What happens if you type
          Code:
          xdotool key backslash
          in your terminal?
          Kubuntu 20.04

          Comment


            #6
            Thanks for the answer.

            If I type

            xdotool: Unknown command: Control+Alt+less
            Run 'xdotool help' if you want a command list

            I obtain a backslash on the next line:

            me@geronimoT460p:~$ xdotool key backslash
            \me@geronimoT460p:~$ \


            But I don't know how to use it to have a backslash whenever I press Ctrl+Alt+less. Any suggestions?

            Comment


              #7
              First, I have a different keyboard and on mine, the "less than" key is shared with the comma key and so using "Ctrl+Alt+less" is difficult for me.

              I'll use Ctrl+Meta+b to illustrate. You can use whatever is more convenient for you providing the shortcut combination doesn't conflict with anything else.

              First, I make the following script using a plain text editor and save it ~/bin as backslash:
              Code:
              #! /usr/bin/env bash
              
              bash -c 'sleep 0.5; xdotool key backslash'
              Right-click on the file in Dolphin and then in Permissions, set it to executable.

              Then, I open System Settings > Custom Shortcuts and make a new one:
              For description, call it backslash or whatever you like.
              In trigger, press the key combination exactly as you'd use it when you're working.
              In action, type the name of whatever you've saved the script as.
              Press Apply. and now, whenever you press the key combination you assigned to the script, a backslash should appear.

              If your specs are good enough, you can reduce or remove the sleep bit altogether.
              Kubuntu 20.04

              Comment


                #8
                @oshunluvr I opened windows10 again and the only information that I could find about my keyboard is that it is
                ``Swiss French
                QWERTZ"

                But when I go in Settings -> Input Devices -> Keyboard -> Layout
                and I choose Add, a window appears. I tried to select first
                ``Limit selection by language = French"
                ``Layout = German (Switzerland)" (since there is no ``French (Switzerland)" at this level)
                ``Variant = French (Switzerland)"

                And I end up with the keyboard layout that I have since the beginning without Ctrl+Alt+less giving me a backslahs :,(
                My guess would be that Windows has its own directories of keyboard layouts and that there is no Linux equivalent for now. So I will try to investigate more with this xbindkey and xdotool.

                By the way, could you please move this thread to the Coding/Scripting subforum?

                Thanks again for you help and have a nice day.

                Comment


                  #9
                  @chimak111 Thanks for the answer! I see it only now. I will try your solution tomorrow. For now I need to sleep. But speaking of sleep, I'm not sure to understand the sleep very well. What do you mean if my specs are good? If I remember well, sleep just doesn't do anything for a while. Why would I add this (the question is sincere, I'm sure there's a reason, but I don't understand it).

                  Best

                  Comment


                    #10
                    Edit: This maybe the best way since it's part of KDE:

                    System Settings > Custom Settings > Edit > New > Global Shortcut > Send Keyboard Input

                    Under Comment put something useful
                    Under Trigger use the shortcut that you'll use. I went with Ctrl+Meta+B (and got a message that it's already in use. I reassigned it to the current shortcut because I don't need the older one.)
                    Under Action, simply press the key that gives you the backslash on your system.
                    Click Apply.

                    You should be done. No need for xdotool (or sleep)

                    For longer or more complicated text, see the image I've attached. Also see https://www.kubuntuforums.net/showth...hlight=autokey for someone who uses "the BÉPO keyboard".

                    Please ignore all the rest below!

                    Re. the sleep bit, I found that some xdotool commands just wouldn't work. After searching around, I came across the suggestion to use sleep.

                    My understanding of https://stackoverflow.com/questions/...nning-commands is that the initial sleep ensures that the keys pressed (Ctrl+Meta+B in my example) are completely released before xdotool is asked to do its work.

                    http://tuxradar.com/content/xdotool-script-your-mouse has some uses of sleep as well.

                    But, as I mentioned, you can reduce the sleep value or get rid of it based on your experience on your system.

                    ****
                    By the way, KDE has something built-in which you could try as well. Here's one discussion on the topic: https://forum.kde.org/viewtopic.php?f=66&t=127482.
                    Attached Files
                    Last edited by chimak111; Jan 06, 2018, 10:49 PM.
                    Kubuntu 20.04

                    Comment


                      #11
                      Thank you for your answer chimak111.

                      I did what you recommended but it's not working everywere: I can get the backslash by pressing Ctrl+Alt+less in some cases (inside firefox for instance) but I don't get it for texmaker (that I use for latex), or inside the terminal
                      I must say I'm a bit lost.

                      Any idea?

                      Have a nice day

                      Comment


                        #12
                        The custom shortcut works for me in konsole. I don't use texmaker and so can't comment.

                        Why don't you try the xdotool route as well? Maybe you'll have better luck?
                        Kubuntu 20.04

                        Comment


                          #13
                          Hi chimak111. Thanks a lot for your answer. I tried the xdotool way as you presented it before but I obtained exactly the same result as the other day. I can use the shortcut in firefox for instance, but not in texmaker or in the terminal. I'm really confused.

                          But thanks anyway.

                          Comment

                          Working...
                          X