How to create a symbol for LMB (left mouse clicking) or RMB (right mouse clicking) in LaTeX?

Since you have already created these images, you just need to include them in your document. Make sure that the bounding box around the images are tight, otherwise you'll end up with too much white space around them.

To include the image, use

\usepackage{graphicx}% http://ctan.org/pkg/graphicx

in your document preamble, together with commands like

\newcommand{\LMB}{\includegraphics[height=.8\baselineskip]{LMB}}% Left Mouse Button
\newcommand{\RMB}{\includegraphics[height=.8\baselineskip]{RMB}}% Right Mouse Button

where your buttons are exported from Adobe Illustrator as LMB.pdf and RMB.pdf (if you're using PDFLaTeX.

The above commands allow you to use \LMB and \RMB in your text, and prints the images at 80% of the baseline height. Depending on your usage, you may want to also include the xspace package and insert \xspace after each command. That would ease your use of \LMB/\RMB without having to always add a control space \ after it.


I came here via google in the hope that the page might be overrun by rodents, I was dissapointed... but the next googler need not have to endure such an anticlimax. Even if they seek the more pointy variety.

mice

The documentation is embedded within the code, this was copy/pasted from a package I maintain for personal use. All the \begin/end{macrocode} bits are stripped off but it needlessly creates a compeng family/name space. Although this should not annoy the final user. If there is interest in the package let me know I could post it on CTAN after cleaning up the file somewhat, it mostly contains icons for use in GUI's and documentation.

\documentclass[tikz]{standalone}

\usetikzlibrary{calc}
\usetikzlibrary{fadings}

\newlength\len
\setlength\len{1em}

\makeatletter
% To accomodate minor geometry changes within the mouse one needs to optionally enable and disable separate paths.
% The following `if` allows for the middle wheel of the mouse to be activated/deactiveted as necessary.
\newif\if@ce@mouse@wheel
% Open up a tikzset statement and start assigning the necessary keys for the computer mouse pic.
\tikzset{
% We start off with the initial definition of the pic which simply maps to another key which sets the `.code` handler.
 computer mouse/.pic={\tikzset{compeng/mouse={#1}}},
% Although unusual for a pic one also provides a global style option that may modify at some later time.
 every computer mouse/.style={compeng/mouse/setup/.append style={#1}},
% Within my own style sheet I provide a package name space and this has been carried through here. 
% It will only affect you should you start to meddle with the code base. 
% I should've removed it but didn't bother
 compeng/.is family,
 compeng, % Ensure this becomes absolute
% Initially a family is setup for the mouse under compeng, providing a contained name space for various purposes.
 mouse/.is family,
 mouse/.search also={/tikz, /pgf},
 mouse/.style={
  compeng/mouse/.cd,
  setup,
  #1,
  source,
 },
% One provides the `setup` key to allow for the `classic` and `modern` keys discussed later.
% This basically provides one with global options to the pic that one may set using the `every computer mouse` key defined earlier.
 mouse/.cd,
 setup/.style={},
% The following snippet contructs the mouse, this is done by filling various areas nd then tracing the borders after wards.
% I initially tried making every part separately drawable but this failed on due to the fadings and shadings clashing e.g. lines where faded aswell, there were wierd overlaps and so forth.
 source/.code={
   \fill[compeng/mouse/every mouse] let \n{radius}={0.3*\len}, \n{Radius}={0.4*\len} in  
              (0,0.5*\len)                                                                                                    % Top dead Center
              -- (-\n{Radius}+\n{radius}, 0.5*\len) .. controls (-\n{Radius}, 0.5*\len) .. (-\n{Radius}, 0.5*\len-\n{radius}) % Upper Left Corner
              -- (-\n{Radius},-0.1*\len) arc(180:360:\n{Radius})                                                              % Base
              -- ( \n{Radius}, 0.5*\len-\n{radius}) .. controls ( \n{Radius}, 0.5*\len) .. ( \n{Radius}-\n{radius}, 0.5*\len) % Upper right Corner
              -- cycle
              (0,0) -- (0,0.5*\len);
   \fill[compeng/mouse/every lmb] let \n{radius}={0.3*\len}, \n{Radius}={0.4*\len} in 
        (0,0) |- (-0.4*\len+\n{radius}, 0.5*\len) .. controls (-0.4*\len, 0.5*\len) .. (-0.4*\len, 0.5*\len-\n{radius}) -- (-0.4*\len,-0.1*\len) 
   %            arc(180:225:\n{Radius}) 
              -- cycle;
   \fill[compeng/mouse/every rmb] let \n{radius}={0.3*\len}, \n{Radius}={0.4*\len} in 
        (0,0) |- ( 0.4*\len-\n{radius}, 0.5*\len) .. controls ( 0.4*\len, 0.5*\len) .. ( 0.4*\len, 0.5*\len-\n{radius}) -- ( 0.4*\len,-0.1*\len) 
   %            arc(0:-45:\n{Radius}) 
              -- cycle;
   \if@ce@mouse@wheel % Pretty sure I've used if's in paths before ? It wouldn't work here
     \fill[compeng/mouse/every mmb] ( 0,0.25*\len) ellipse ({0.075*\len} and {0.15*\len});
   \fi
   \path[draw, line cap =round] let \n{radius}={0.3*\len}, \n{Radius}={0.4*\len} in  
              (0,0.5*\len)                                                                                                    % Top dead Center
              -- (-\n{Radius}+\n{radius}, 0.5*\len) .. controls (-\n{Radius}, 0.5*\len) .. (-\n{Radius}, 0.5*\len-\n{radius}) % Upper Left Corner
              -- (-\n{Radius},-0.1*\len) arc(180:360:\n{Radius})                                                              % Base
              -- ( \n{Radius}, 0.5*\len-\n{radius}) .. controls ( \n{Radius}, 0.5*\len) .. ( \n{Radius}-\n{radius}, 0.5*\len) % Upper right Corner
              -- cycle;
   \if@ce@mouse@wheel % Pretty sure I've used if's in paths before ? It wouldn't work here
     \path[draw, line cap =round] 
        (0,-0.025*\len) -- ( 0,0.1*\len)  
        ( 0,0.25*\len) ellipse ({0.075*\len} and {0.15*\len}) 
        ( 0,0.4*\len) -- (0,0.5*\len);
   \else
     \path[draw, line cap =round] 
        (0,-0.025*\len) -- (0,0.5*\len);
   \fi;
 },
% It's handy to be able to alternate between a 2 or 3 button mice in some document contexts and the following provides a means of toggling the middle button on or off.
% The user may do this within a given tikzpicture or globally for a document by setting the `every computer mouse` key to either classic (2 button mouse) or modern (3 button mouse), using the usual `\tikzset` command e.g. \tikzset{every computer mouse={classic}}
 wheel/.is if=@ce@mouse@wheel,
 wheel/.default=true,
 wheel=true, % note that using /.initial store the value elsewhere and does not set the if
 modern/.style={wheel=true},
 classic/.style={wheel=false},
% The mouse is setup with a gray base colour that blends nicely into the buttons. 
% Fiddling with the gradient too much here makes it all rather horrid but the user is free to do so.
 every mouse/.style={compeng/mouse/.cd, mouse color},
 mouse color/.style 2 args={
     top color   =#1,
     bottom color=#2!70!#1},
 mouse color/.default={white}{black},
% The middle mouse is simply represented by an ellipse. 
% The default colour here is simply horrid but it's the best I managed to do.
 every mmb/.style={compeng/mouse/.cd, mmb color},
 mmb color/.style n args={2}{
                 inner color  = #1!70!#2,
                 outer color  = #1!50!#2,
 },
 mmb color/.default={white}{black},
% The left mouse button is setup as a shaded and faded a strip covering the left half of the mouse.
% The shading is tilted some what to enhance the gradient somewhat.
 every lmb/.style={compeng/mouse/.cd, lmb color},
 lmb color/.style n args={3}{
   fill          = #2,
   top    color  = #1, % black!70!white,
   bottom color  = #3!70!#2, % Do not adjust
   shading angle = 10,
   fit fading    = true,
   path fading   = south,
   fading angle  = 10,
 },
 lmb color/.default={gray}{white}{black},
% The right mouse button is similarly constructed
 every rmb/.style={compeng/mouse/.cd, rmb color},
% The commented code below is mostly for experimentation purposes, but it could, with extention, allow one to do things like annotate how long the button is held down for or be used to indicate double and single clicks.
%  rmb/.is choice,
%  rmb/click/.style={rmb color={red}{white}{black}},
%  %rmb/.hold={rmb color},
%  %rmb/.release={rmb color},
%  rmb/rest/.style={rmb color},
%  rmb/.default=rest,
 rmb color/.style n args={3}{
                 fill          = #2,
                 top    color  = #1,  % black!70!white,
                 bottom color  = #3!70!#2,
                 shading angle = -10,
                 fit fading    = true,
                 path fading   = south,
                 fading angle  = -10,
 },
 rmb color/.default={gray}{white}{black},
% Presently any clicking action is represented by colouring the appropriate buttons.
 lmb/.style  = {every lmb/.append style={lmb color={blue}{white}{black}}},
 rmb/.style  = {every rmb/.append style={rmb color={red}{white}{black}}},
 mmb/.style  = {every mmb/.append style={mmb color={cyan}{black}}},
 bmb/.style  = {every lmb/.append style={lmb color={purple}{white}{black}},
                every rmb/.append style={rmb color={purple}{white}{black}}},
% The following key/color combinations should probably not be used nor made available but are here for convenience.
 amb/.style  = {every lmb/.append style={lmb color={purple!60!cyan}{white}{black}},
                every rmb/.append style={rmb color={purple!60!cyan}{white}{black}},
                every mmb/.append style={mmb color={purple!60!cyan}{black}}},
 mlmb/.style = {every lmb/.append style={lmb color={blue!60!cyan}{white}{black}},
                every mmb/.append style={mmb color={blue!60!cyan}{black}}},
 mrmb/.style = {every rmb/.append style={rmb color={red!60!cyan}{white}{black}},
                every mmb/.append style={mmb color={red!60!cyan}{black}}},
}
\makeatother

\begin{document}

\begin{tikzpicture}
\draw[every computer mouse={classic}] 
   let \n{len}={1.5em} in
   pic at (180:\n{len}) {computer mouse={lmb}} 
   pic at ( 90:\n{len}) {computer mouse={}} 
   pic at (  0:\n{len}) {computer mouse={rmb}} 
   pic at (270:\n{len}) {computer mouse={bmb}};
\draw[every computer mouse={modern}] 
   let \n{len}={3em} in
   pic at (0,0) {computer mouse} 
   pic at (180:\n{len}) {computer mouse={lmb}} 
   pic at (135:\n{len}) {computer mouse={lmb,mmb}} 
   pic at ( 90:\n{len}) {computer mouse={mmb}} 
   pic at ( 45:\n{len}) {computer mouse={mmb,rmb}} 
   pic at (  0:\n{len}) {computer mouse={rmb}} 
   pic at (225:\n{len}) {computer mouse={mlmb}}
   pic at (270:\n{len}) {computer mouse={amb}}
   pic at (315:\n{len}) {computer mouse={mrmb}};
\end{tikzpicture}
\end{document}

Tags:

Diagrams