2 package net.sourceforge.guacamole.net.input;
5 * Guacamole - Pure JavaScript/HTML VNC Client
6 * Copyright (C) 2010 Michael Jumper
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.
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.
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/>.
22 import javax.servlet.ServletRequest;
23 import net.sourceforge.guacamole.GuacamoleException;
24 import org.w3c.dom.Element;
25 import net.sourceforge.guacamole.event.KeyEvent;
27 import net.sourceforge.guacamole.net.GuacamoleSession;
28 import net.sourceforge.guacamole.net.XMLGuacamoleServlet;
29 import net.sourceforge.guacamole.vnc.VNCException;
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.
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
41 * pressed: Whether the key was pressed (1) or released (0).
42 * keysym: The integer representing the corresponding X11 keysym.
44 * @author Michael Jumper
47 public class Key extends XMLGuacamoleServlet {
50 protected void handleRequest(GuacamoleSession session, ServletRequest request, Element root) throws GuacamoleException {
53 int index = Integer.parseInt(request.getParameter("index"));
54 boolean pressed = request.getParameter("pressed").equals("1");
55 int keysym = Integer.parseInt(request.getParameter("keysym"));
59 session.getClient().send(new KeyEvent(index, keysym, pressed));
61 catch (GuacamoleException e) {
62 throw new GuacamoleException("Error sending key event to server: " + e.getMessage(), e);