Added version variable to build script and index.html. Mouse over on bowl now reveals...
[guacamole.git] / src / net / sourceforge / guacamole / net / input / Key.java
1
2 package net.sourceforge.guacamole.net.input;
3
4 /*
5  *  Guacamole - Pure JavaScript/HTML VNC Client
6  *  Copyright (C) 2010  Michael Jumper
7  *
8  *  This program is free software: you can redistribute it and/or modify
9  *  it under the terms of the GNU Affero General Public License as published by
10  *  the Free Software Foundation, either version 3 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU Affero General Public License for more details.
17  *
18  *  You should have received a copy of the GNU Affero General Public License
19  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 import javax.servlet.ServletRequest;
23 import net.sourceforge.guacamole.GuacamoleException;
24 import org.w3c.dom.Element;
25 import net.sourceforge.guacamole.event.KeyEvent;
26
27 import net.sourceforge.guacamole.net.GuacamoleSession;
28 import net.sourceforge.guacamole.net.XMLGuacamoleServlet;
29 import net.sourceforge.guacamole.vnc.VNCException;
30
31 /**
32  * Servlet which accepts keyboard input events, forwards these events to the
33  * VNC client associated with the session, and returns the result (if any)
34  * to the HTTP client via XML.
35  *
36  * This servlet takes three parameters:
37  *      index:    The event index. As HTTP requests may arrive out of order,
38  *                this index provides the event queue with a means of sorting
39  *                events, and determining if events are missing. The first
40  *                event has index 0.
41  *      pressed:  Whether the key was pressed (1) or released (0).
42  *      keysym:   The integer representing the corresponding X11 keysym.
43  *
44  * @author Michael Jumper
45  */
46
47 public class Key extends XMLGuacamoleServlet {
48
49     @Override
50     protected void handleRequest(GuacamoleSession session, ServletRequest request, Element root) throws GuacamoleException {
51
52         // Event parameters
53         int index = Integer.parseInt(request.getParameter("index"));
54         boolean pressed = request.getParameter("pressed").equals("1");
55         int keysym = Integer.parseInt(request.getParameter("keysym"));
56
57         // Send/queue event
58         try {
59             session.getClient().send(new KeyEvent(index, keysym, pressed));
60         }
61         catch (GuacamoleException e) {
62             throw new GuacamoleException("Error sending key event to server: " + e.getMessage(), e);
63         }
64
65     }
66 }
67