001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // This program is free software; you can redistribute it and/or modify
004: // it under the terms of the GNU General Public License and GNU Library
005: // General Public License as published by the Free Software Foundation;
006: // either version 2, or (at your option) any later version.
007: //
008: // This program is distributed in the hope that it will be useful,
009: // but WITHOUT ANY WARRANTY; without even the implied warranty of
010: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: // GNU General Public License and GNU Library General Public License
012: // for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // and GNU Library General Public License along with this program; if
016: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
017: // MA 02139, USA.
018: //
019: ///////////////////////////////////////////////////////////////////////////////
020:
021: package org.rdesktop.server.rdp;
022:
023: import java.awt.*;
024: import java.awt.event.*;
025: import java.util.Collections;
026:
027: import org.rdesktop.server.rdp.keymapping.*;
028:
029: public class RdpInput extends RdpAbstractInput {
030: public RdpInput(RdpProto proto, RdpAbstractDesktopCanvas canvas,
031: KeyCode_FileBased keyMap) {
032: super (proto, canvas, keyMap);
033:
034: KeyboardFocusManager.getCurrentKeyboardFocusManager()
035: .setDefaultFocusTraversalKeys(
036: KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
037: Collections.EMPTY_SET);
038: KeyboardFocusManager.getCurrentKeyboardFocusManager()
039: .setDefaultFocusTraversalKeys(
040: KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
041: Collections.EMPTY_SET);
042: }
043:
044: public RdpInput(RdpProto proto, RdpAbstractDesktopCanvas canvas,
045: String keyMap) {
046: super (proto, canvas, keyMap);
047:
048: KeyboardFocusManager.getCurrentKeyboardFocusManager()
049: .setDefaultFocusTraversalKeys(
050: KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
051: Collections.EMPTY_SET);
052: KeyboardFocusManager.getCurrentKeyboardFocusManager()
053: .setDefaultFocusTraversalKeys(
054: KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
055: Collections.EMPTY_SET);
056: }
057:
058: protected void doLockKeys() {
059: if (RdpOptions.useLockingKeyState == false) {
060: return;
061: }
062:
063: try {
064: Toolkit tk = Toolkit.getDefaultToolkit();
065:
066: if (tk.getLockingKeyState(KeyEvent.VK_CAPS_LOCK) != m_capsLockOn) {
067: m_capsLockOn = !m_capsLockOn;
068: sendScancode(getTime(), RDP_KEYPRESS, 0x3a);
069: sendScancode(getTime(), RDP_KEYRELEASE, 0x3a);
070:
071: }
072:
073: if (tk.getLockingKeyState(KeyEvent.VK_NUM_LOCK) != m_numLockOn) {
074: m_numLockOn = !m_numLockOn;
075: sendScancode(getTime(), RDP_KEYPRESS, 0x45);
076: sendScancode(getTime(), RDP_KEYRELEASE, 0x45);
077:
078: }
079:
080: if (tk.getLockingKeyState(KeyEvent.VK_SCROLL_LOCK) != m_scrollLockOn) {
081: m_scrollLockOn = !m_scrollLockOn;
082: sendScancode(getTime(), RDP_KEYPRESS, 0x46);
083: sendScancode(getTime(), RDP_KEYRELEASE, 0x46);
084: }
085: } catch (Exception e) {
086: RdpOptions.useLockingKeyState = false;
087: }
088: }
089:
090: public void clearKeys() {
091: super .clearKeys();
092:
093: if ((m_lastKeyEvent != null)
094: && (m_lastKeyEvent.isAltGraphDown() == true)) {
095: sendScancode(getTime(), RDP_KEYRELEASE,
096: 0x38 | KeyCode.SCANCODE_EXTENDED); //r.alt
097: }
098: }
099:
100: public void setKeys() {
101: super .setKeys();
102:
103: if ((m_lastKeyEvent != null)
104: && (m_lastKeyEvent.isAltGraphDown() == true)) {
105: sendScancode(getTime(), RDP_KEYPRESS,
106: 0x38 | KeyCode.SCANCODE_EXTENDED); //r.alt
107: }
108: }
109:
110: public void addInputListeners() {
111: super .addInputListeners();
112:
113: m_canvas
114: .addMouseWheelListener(new RdpDesktopMouseWheelAdapter());
115: }
116:
117: public boolean handleShortcutKeys(long time, KeyEvent e,
118: boolean pressed) {
119: if (super .handleShortcutKeys(time, e, pressed) == true) {
120: return true;
121: }
122:
123: if (m_altDown == false) {
124: return false; // all of the below have ALT on
125: }
126:
127: switch (e.getKeyCode()) {
128: case KeyEvent.VK_MINUS: // for laptops that can't do Ctrl+Alt+Minus
129: {
130: if (m_ctrlDown == true) {
131: if (pressed == true) {
132: sendScancode(time, RDP_KEYRELEASE, 0x1d); // Ctrl
133: sendScancode(time, RDP_KEYPRESS,
134: 0x37 | KeyCode.SCANCODE_EXTENDED); // PrtSc
135: } else {
136: sendScancode(time, RDP_KEYRELEASE,
137: 0x37 | KeyCode.SCANCODE_EXTENDED); // PrtSc
138: sendScancode(time, RDP_KEYPRESS, 0x1d); // Ctrl
139: }
140: }
141:
142: break;
143: }
144: default: {
145: return false;
146: }
147: }
148:
149: return true;
150: }
151:
152: class RdpDesktopMouseWheelAdapter implements MouseWheelListener {
153: public void mouseWheelMoved(MouseWheelEvent e) {
154: int time = getTime();
155:
156: if (m_rdp != null) {
157: if (e.getWheelRotation() < 0) // up
158: {
159: m_rdp.sendInput(time, RDP_INPUT_MOUSE,
160: MOUSE_FLAG_BUTTON4 | MOUSE_FLAG_DOWN, e
161: .getX(), e.getY());
162: } else // down
163: {
164: m_rdp.sendInput(time, RDP_INPUT_MOUSE,
165: MOUSE_FLAG_BUTTON5 | MOUSE_FLAG_DOWN, e
166: .getX(), e.getY());
167: }
168: }
169: }
170: }
171: }
|