View Javadoc

1   /*
2    * @(#)$Id: KeyboardSimulation.java 689 2009-07-22 00:10:27Z bsigner $
3    * 
4    *
5    * Author		:	Michele Croci, mcroci@gmail.com
6    *
7    * Purpose		:   Simulate keyboard
8    *
9    * -----------------------------------------------------------------------
10   *
11   * Revision Information:
12   *
13   * Date				Who			Reason
14   *
15   * Nov 27, 2007		crocimi		Initial Release
16   * Nov 27, 2008     kurmannu    Cleanup, Refactoring
17   *
18   * -----------------------------------------------------------------------
19   *
20   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
21   *
22   * This software is the proprietary information of ETH Zurich.
23   * Use is subject to license terms.
24   * 
25   */
26  
27  
28  package org.ximtec.igesture.geco.action;
29  
30  import org.sigtec.util.Constant;
31  import org.ximtec.igesture.core.ResultSet;
32  import org.ximtec.igesture.event.GestureAction;
33  import org.ximtec.igesture.io.keyboard.Key;
34  import org.ximtec.igesture.io.keyboard.Win32KeyboardProxy;
35  
36  
37  /**
38   * @version 0.9, Mar 2007
39   * @author Michele Croci, mcroci@gmail.com
40   * @author Ueli Kurmann, ueli.kurmann@bbv.ch
41   */
42  public class KeyboardSimulation implements GestureAction {
43  
44     private Key[] keys;
45  
46  
47     /**
48      * Constructor.
49      * 
50      * @param keys the keys corresponding to the action
51      */
52     public KeyboardSimulation(String keys) {
53        setKeys(Key.parseKeyList(keys));
54     }// KeyboardSimulationAction
55  
56  
57     public void actionPerformed(ResultSet resultSet) {
58        Win32KeyboardProxy.pressKey(keys);
59     } // run
60  
61  
62     /**
63      * Set the keys to be pressed.
64      * 
65      * @param keys the keys corresponding to the action
66      */
67     public void setKeys(Key[] keys) {
68        this.keys = keys;
69     } // setKeys
70  
71  
72     /**
73      * Returns the selected keys
74      * 
75      * @return the keys to be pressed
76      */
77     public Key[] getAllKeys() {
78        return keys;
79     }// toString
80  
81  
82     /**
83      * Returns a description of the action
84      * 
85      * @return the keys to be pressed
86      */
87     public String toString() {
88  
89        StringBuilder sb = new StringBuilder();
90        for (Key key : keys) {
91           sb.append(key.toString());
92           sb.append(Constant.PLUS);
93        }
94  
95        return sb.length() > 0 ? sb.deleteCharAt(sb.length() - 1).toString() : sb
96              .toString();
97     }// toString
98  
99  }