View Javadoc

1   /*
2    * @(#)$Id: Win32KeyboardProxy.java 689 2009-07-22 00:10:27Z bsigner $
3    *
4    * Author       :   Ueli Kurmann, igesture@uelikurmann.ch
5    *
6    * Purpose      : 	A keyboard simulator.
7    *
8    * -----------------------------------------------------------------------
9    *
10   * Revision Information:
11   *
12   * Date             Who         Reason
13   *
14   * Mar 09, 2007     ukurmann    Initial Release
15   * Mar 22, 2007     bsigner     Cleanup
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.logging.Logger;
30  
31  
32  
33  /**
34   * A keyboard simulator.
35   * 
36   * @version 1.0, Dec 2006
37   * @author Ueli Kurmann, igesture@uelikurmann.ch
38   * @author Beat Signer, signer@inf.ethz.ch
39   */
40  public class Win32KeyboardProxy {
41  
42     private static final Logger LOGGER = Logger
43           .getLogger(Win32KeyboardProxy.class.getName());
44  
45     private static KeyboardUtils keyboardUtils = new KeyboardUtils();
46  
47  
48     /**
49      * Simulates a keyboard input
50      * @param keys the keys
51      */
52     public static void pressKey(Key... keys) {
53        
54        for (Key key : keys) {
55           LOGGER.info("Key: " + key.toString() + "; State: " + Key.KEY_DOWN.toString());
56           keyboardUtils.keyEvent(key, Key.KEY_DOWN);
57        }
58  
59        for (Key key : keys) {
60           LOGGER.info("Key: " + key.toString() + "; State: " + Key.KEY_UP.toString());
61           keyboardUtils.keyEvent(key, Key.KEY_UP);
62        }
63  
64     } // pressKey
65  
66  }