jjarvis
Posts: 11
Joined: Tue May 29, 2012 8:47 pm

Using the keyboard as mouse

Tue Jan 01, 2013 3:53 pm

When X having both a mouse and a keyboard attached means there are no spare USB ports... so I thought wouldn't it be nice if the keyboard could be used to do this. Well it can!

I followed Adriano's instructions in this post http://forum.lxde.org/viewtopic.php?f=4&t=31747 and it worked a treat. Make sure you get the XML inserted into the <keyboard> section.

It depends on xwit and xdotool:

Code: Select all

sudo apt-get install xwit xdotool
Now Ctrl+Alt+Keypad buttons moves the cursor.

bgirardot
Posts: 517
Joined: Wed Oct 10, 2012 6:20 am
Location: Switzerland

Re: Using the keyboard as mouse

Tue Jan 01, 2013 4:43 pm

Thank you very much for the info.

Out of curiosity, which xml file did you edit to put the keybindings in?

bgirardot
Posts: 517
Joined: Wed Oct 10, 2012 6:20 am
Location: Switzerland

Re: Using the keyboard as mouse

Wed Jan 02, 2013 3:03 pm

Just to follow up on my own post for posterity's sake:

The xml file you need to edit in Raspbian is:

~/.config/openbox/lxde-rc.xml

(the ~/ part means in the current user's home directory)

And from the post linked to in the original post here is the example set of keybindings:

Code: Select all

    <!-- Controlando o MOUSE via LXDE com XWIT -->
      <!-- Keybinding for MOUSE CONTROL RIGHT DOWN-->
      <keybind key="C-A-KP_3">
       <action name="Execute">
             <command>xwit -root -rwarp 5 5</command>
       </action>
      </keybind>

      <!-- Keybinding for MOUSE CONTROL RIGHT UP-->
      <keybind key="C-A-KP_9">
       <action name="Execute">
             <command>xwit -root -rwarp 5 -5</command>
       </action>
      </keybind>

      <!-- Keybinding for MOUSE CONTROL LEFT DOWN-->
      <keybind key="C-A-KP_1">
       <action name="Execute">
             <command>xwit -root -rwarp -5 5</command>
       </action>
      </keybind>

      <!-- Keybinding for MOUSE CONTROL LEFT UP-->
      <keybind key="C-A-KP_7">
       <action name="Execute">
             <command>xwit -root -rwarp -5 -5</command>
       </action>
      </keybind>

      <!-- Keybinding for MOUSE CONTROL LEFT-->
      <keybind key="C-A-KP_4">
       <action name="Execute">
             <command>xwit -root -rwarp -5 0</command>
       </action>
      </keybind>

      <!-- Keybinding for MOUSE CONTROL RIGHT-->
      <keybind key="C-A-KP_6">
       <action name="Execute">
             <command>xwit -root -rwarp 5 0</command>
       </action>
      </keybind>

      <!-- Keybinding for MOUSE CONTROL UP-->
      <keybind key="C-A-KP_8">
       <action name="Execute">
             <command>xwit -root -rwarp 0 -5</command>
       </action>
      </keybind>

      <!-- Keybinding for MOUSE CONTROL DOWN-->
        
      <keybind key="C-A-KP_2">
       <action name="Execute">
                <command>xwit -root -rwarp 0 5</command>
       </action>
      </keybind>

      <!-- Keybinding for MOUSE CONTROL DOWN FAST-->
        
      <keybind key="S-C-A-KP_2">
       <action name="Execute">
                <command>xwit -root -rwarp 0 25</command>
       </action>
      </keybind>

      <!-- Keybinding for MOUSE CONTROL RIGHT CLICK-->
      <keybind key="C-A-KP_0">
       <action name="Execute">
             <command>xdotool click 3</command>
       </action>
      </keybind>

      <!-- Keybinding for MOUSE CONTROL MIDLE CLICK-->
      <keybind key="C-A-KP_Decimal">
       <action name="Execute">
             <command>xdotool click 2</command>
       </action>
      </keybind>

      <!-- Keybinding for MOUSE CONTROL LEFT CLICK-->
      <keybind key="C-A-KP_Enter">
       <action name="Execute">
             <command>xdotool click 1</command>
       </action>
      </keybind>

      <!--
          Adriano H. Hedler - LXDE Translation to Portuguese-BR Helper
          Accessibility Option on LXDE
          Brasil - Paraná - Curitiba
          Site: www.templosite.com 
      -->

      <!-- Fim seção CONROLE DO MOUSE COMUM -->
One thing to note: If you are running headless and tunneling X this method of keyboard mouse control does not seem to work, and until you actually hook the RPi up to a monitor you will not have the ~/.config/openbox directory or the associated xml file. You can copy it from its source location to your home directory by hand if you really want to set this up headless first:

Code: Select all

mkdir ~/.config/openbox
cp /etc/xdg/openbox/LXDE/rc.xml  ~/.config/openbox/lxde-rc.xml

jjarvis
Posts: 11
Joined: Tue May 29, 2012 8:47 pm

Re: Using the keyboard as mouse

Thu Jan 03, 2013 5:52 pm

Thanks for following up with the additional info about the correct filename and use when pi is not attached to a physical display.

sdjf
Posts: 1395
Joined: Fri Mar 16, 2012 5:20 am
Location: California
Contact: Website

Re: Using the keyboard as mouse

Fri Oct 11, 2013 2:49 am

Just reporting that I have been using this on a headless Pi, where I connect to my Pi over ethernet. All the setup has been done when logged in over ssh.

Maybe it depends on what Operating System you are running, I am running Arch with Openbox as the desktop environment right now.

But what I have found is that while the xwit utility is working perfectly to move the pointer on the display, I have not yet been able to successfully get the keybindings for mouse clicks to work, whether I use xdotool or xte (which can perform similar mouse click actions and is part of the xaccessibility package).

The strange thing is that I can type the xdotool and equivalent xte commands in another display on another box that is ssh'd into my Pi at the same time, and my VNC display on the main box does act as if I had actually clicked a mouse on it!

Still trying to figure out why the keybindings for xwit are working fine, but I cannot get them to work for xdotool or xte at this point.

Oh, in Arch, the relevant config file is in ~/.config/openbox/rc.xml
FORUM TIP: To view someone's posting history, sign in, click on their user name, then on "Search User's Posts." || Running ArchLinuxArm on Model 2B and 512MB Model B

sdjf
Posts: 1395
Joined: Fri Mar 16, 2012 5:20 am
Location: California
Contact: Website

Re: Using the keyboard as mouse

Mon Oct 21, 2013 8:21 pm

One more thing I want to mention. It is not necessary to have ever hooked up the Pi to a physical display to get this utility working, I have been using it on a Pi for which that is the case. I expect to be getting a physical display soon, so we shall see if my keybinding problem goes away when there is a physical display attached to the Pi.

When I installed openbox (at least in Arch), I believe it automatically generated the rc.xml file. If it did not (my memory could be wrong), then all I had to do was create the appropriate directory and subdirectory, and put a copy of a standard openbox rc.xml file that I had from some other way. I honestly do not recall as I have had openbox so long.
FORUM TIP: To view someone's posting history, sign in, click on their user name, then on "Search User's Posts." || Running ArchLinuxArm on Model 2B and 512MB Model B

asanket05
Posts: 4
Joined: Mon Sep 29, 2014 11:35 am

Re: Using the keyboard as mouse

Wed Oct 22, 2014 7:56 am

i wanted to use a 4 wire resistive touch screen as a wireless mouse through zigbee module, is it possible to operate cursor by taking only hex or binary values through gpio serial communication pins ?

Return to “Advanced users”