View Javadoc

1   /*
2    * @(#)$Id:$
3    *
4    * Author		:	Ueli Kurmann, ueli.kurmann@bbv.ch
5    *                  
6    *
7    * Purpose		: 
8    *
9    * -----------------------------------------------------------------------
10   *
11   * Revision Information:
12   *
13   * Date				Who			Reason
14   *
15   * 28.11.2008			ukurmann	Initial Release
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
23   * 
24   */
25  
26  
27  package org.ximtec.igesture.io.keyboard;
28  
29  import java.util.ArrayList;
30  import java.util.List;
31  
32  /**
33   * Key definition. This enum is used to simluate keyboard input.
34   * @version 1.0 28.11.2008
35   * @author Ueli Kurmann
36   */
37  public enum Key {
38     
39     
40     
41     SHIFT(0x10), CONTROL(0x11),CTRL(0x11), ALT(0x12), DELETE(0x2E), CLEAR(0x0C), BACKSPACE(0x08), TAB(
42           0x09), ENTER(0x0D), ESCAPE(0x1B), SPACE(0x20),
43  
44     VK_0(0x30), VK_1(0x31), VK_2(0x32), VK_3(0x33), VK_4(0x34), VK_5(0x35), VK_6(
45           0x36), VK_7(0x37), VK_8(0x38), VK_9(0x39),
46  
47     A(0X41), B(0X42), C(0X43), D(0X44), E(0X45), F(0X46), G(0X47), H(0X48), I(
48           0X49), J(0X4A), K(0X4B), L(0X4C), M(0X4D), N(0X4E), O(0X4F), P(0X50), Q(
49           0X51), R(0X52), S(0X53), T(0X54), U(0X55), V(0X56), W(0X57), X(0X58), Y(
50           0X59), Z(0X5A),
51  
52     F1(0x70), F2(0x71), F3(0x72), F4(0x73), F5(0x74), F6(0x75), F7(0x76), F8(0x77), F9(
53           0x78), F10(0x79), F11(0x7A), F12(0x7B),
54  
55     LEFT(0x25), UP(0x26), RIGHT(0x27), DOWN(0x28), PAGE_UP(0x21), PAGE_DOWN(0x22), END(
56           0x23), HOME(0x24),
57  
58     KEY_DOWN(0x0), KEY_UP(0x2);
59  
60     private static final String REGEX = "\\+";
61     private static final String KEY_NOT_RECOGNISED = "Key not recognised!";
62     
63     private int keyId;
64  
65     /**
66      * Private constructor to initialize the enum. 
67      * @param keyId
68      */
69     private Key(int keyId) {
70        this.keyId = keyId;
71     }
72  
73     /**
74      * Returns the integer representation of the key.
75      * @return the integer representation of the key.
76      */
77     public int getKeyId() {
78        return keyId;
79     }
80     
81     /**
82      * Parses a string list of keys
83      * Delimiter: +
84      * E.g.: ALT + TAB  
85      * @param keys
86      * @return
87      */
88     public static Key[] parseKeyList(String keys) throws IllegalArgumentException {
89        List<Key> codes = new ArrayList<Key>();
90  
91        for (String keyAsString : keys.split(REGEX)) {
92           
93           try {
94              keyAsString = keyAsString.trim().toUpperCase();
95              Key key = Key.valueOf(keyAsString);
96              codes.add(key);
97           }
98           catch (Exception e) {
99              throw new IllegalArgumentException(KEY_NOT_RECOGNISED);
100          }
101          
102       }
103 
104      return codes.toArray(new Key[0]);
105    } // parseKeyList
106 
107 }