comparison src/com/five_ten_sg/connectbot/service/TerminalMonitor.java @ 113:cb3b9b660b3d

depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
author Carl Byington <carl@five-ten-sg.com>
date Wed, 18 Jun 2014 14:24:00 -0700
parents 77ac18bc1b2f
children 13cea57ac61e
comparison
equal deleted inserted replaced
112:77ac18bc1b2f 113:cb3b9b660b3d
4 import android.content.Context; 4 import android.content.Context;
5 import android.content.Intent; 5 import android.content.Intent;
6 import android.content.ServiceConnection; 6 import android.content.ServiceConnection;
7 import android.os.IBinder; 7 import android.os.IBinder;
8 import android.util.Log; 8 import android.util.Log;
9 import android.view.KeyEvent;
10 import android.view.View; 9 import android.view.View;
11 import de.mud.terminal.vt320; 10 import de.mud.terminal.vt320;
12 import java.io.IOException; 11 import java.io.IOException;
13 import java.io.InputStream; 12 import java.io.InputStream;
14 import java.io.OutputStream; 13 import java.io.OutputStream;
37 private static final int MONITORPORT = 6000; 36 private static final int MONITORPORT = 6000;
38 private static final String LOCALHOST = "127.0.0.1"; 37 private static final String LOCALHOST = "127.0.0.1";
39 38
40 private Context parent = null; 39 private Context parent = null;
41 private vt320 buffer = null; 40 private vt320 buffer = null;
42 private TerminalKeyListener keyListener = null;
43 private View view = null; 41 private View view = null;
44 private String init = null; 42 private String init = null;
45 private int start_line = 0; // monitor part of the screen for changes 43 private int start_line = 0; // monitor part of the screen for changes
46 private int end_line = 500; // "" 44 private int end_line = 500; // ""
47 private int start_column = 0; // "" 45 private int start_column = 0; // ""
48 private int end_column = 500; // "" 46 private int end_column = 500; // ""
49 private boolean modified = false; // used to delay screen change notifications 47 private boolean modified = false; // used to delay screen change notifications
50 private boolean moved = false; // used to delay cursor moved notifications 48 private boolean moved = false; // used to delay cursor moved notifications
51 private int to_line = 0; // "" 49 private int to_line = 0; // ""
52 private int to_column = 0; // "" 50 private int to_column = 0; // ""
53 private HashMap<Integer, Integer> keymap = null; 51 private HashMap<Integer, Integer> keymap = null; // map MS VK_ keys to vt320 virtual keys
54 private IBinder bound = null; 52 private IBinder bound = null;
55 private Socket monitor_socket = null; 53 private Socket monitor_socket = null;
56 private InputStream monitor_in = null; 54 private InputStream monitor_in = null;
57 private OutputStream monitor_out = null; 55 private OutputStream monitor_out = null;
58 private MyReader monitor_reader = null; 56 private MyReader monitor_reader = null;
171 Log.i(TAG, "unbound from service"); 169 Log.i(TAG, "unbound from service");
172 } 170 }
173 }; 171 };
174 172
175 173
176 public TerminalMonitor(Context parent, vt320 buffer, TerminalKeyListener keyListener, View view, String init) { 174 public TerminalMonitor(Context parent, vt320 buffer, View view, String init) {
177 this.parent = parent; 175 this.parent = parent;
178 this.buffer = buffer; 176 this.buffer = buffer;
179 this.keyListener = keyListener;
180 this.view = view; 177 this.view = view;
181 this.init = init; 178 this.init = init;
182 // setup the windows->android keymapping 179 // setup the windows->android keymapping
183 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731 180 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731
184 // http://developer.android.com/reference/android/view/KeyEvent.html
185 keymap = new HashMap<Integer, Integer>(); 181 keymap = new HashMap<Integer, Integer>();
186 keymap.put(0x08, KeyEvent.KEYCODE_BACK); // vk_back 182 keymap.put(0x08, vt320.KEY_BACK_SPACE); // vk_back
187 keymap.put(0x09, KeyEvent.KEYCODE_TAB); // vk_tab 183 keymap.put(0x09, vt320.KEY_TAB); // vk_tab
188 keymap.put(0x0d, KeyEvent.KEYCODE_ENTER); // vk_return 184 keymap.put(0x0d, vt320.KEY_ENTER); // vk_return
189 keymap.put(0x1b, KeyEvent.KEYCODE_ESCAPE); // vk_escape 185 keymap.put(0x1b, vt320.KEY_ESCAPE); // vk_escape
190 keymap.put(0x21, KeyEvent.KEYCODE_PAGE_UP); // vk_prior 186 keymap.put(0x21, vt320.KEY_PAGE_UP); // vk_prior
191 keymap.put(0x22, KeyEvent.KEYCODE_PAGE_DOWN); // vk_next 187 keymap.put(0x22, vt320.KEY_PAGE_DOWN); // vk_next
192 keymap.put(0x23, KeyEvent.KEYCODE_MOVE_END); // vk_end 188 keymap.put(0x23, vt320.KEY_END); // vk_end
193 keymap.put(0x24, KeyEvent.KEYCODE_MOVE_HOME); // vk_home 189 keymap.put(0x24, vt320.KEY_HOME); // vk_home
194 keymap.put(0x25, KeyEvent.KEYCODE_DPAD_LEFT); // vk_left 190 keymap.put(0x25, vt320.KEY_LEFT); // vk_left
195 keymap.put(0x26, KeyEvent.KEYCODE_DPAD_UP); // vk_up 191 keymap.put(0x26, vt320.KEY_UP); // vk_up
196 keymap.put(0x27, KeyEvent.KEYCODE_DPAD_RIGHT); // vk_right 192 keymap.put(0x27, vt320.KEY_RIGHT); // vk_right
197 keymap.put(0x28, KeyEvent.KEYCODE_DPAD_DOWN); // vk_down 193 keymap.put(0x28, vt320.KEY_DOWN); // vk_down
198 keymap.put(0x2d, KeyEvent.KEYCODE_INSERT); // vk_insert 194 keymap.put(0x2d, vt320.KEY_INSERT); // vk_insert
199 keymap.put(0x2e, KeyEvent.KEYCODE_DEL); // vk_delete 195 keymap.put(0x2e, vt320.KEY_DELETE); // vk_delete
200 keymap.put(0x70, KeyEvent.KEYCODE_F1); // vk_f1 196 keymap.put(0x70, vt320.KEY_F1); // vk_f1
201 keymap.put(0x71, KeyEvent.KEYCODE_F2); // vk_f2 197 keymap.put(0x71, vt320.KEY_F2); // vk_f2
202 keymap.put(0x72, KeyEvent.KEYCODE_F3); // vk_f3 198 keymap.put(0x72, vt320.KEY_F3); // vk_f3
203 keymap.put(0x73, KeyEvent.KEYCODE_F4); // vk_f4 199 keymap.put(0x73, vt320.KEY_F4); // vk_f4
204 keymap.put(0x74, KeyEvent.KEYCODE_F5); // vk_f5 200 keymap.put(0x74, vt320.KEY_F5); // vk_f5
205 keymap.put(0x75, KeyEvent.KEYCODE_F6); // vk_f6 201 keymap.put(0x75, vt320.KEY_F6); // vk_f6
206 keymap.put(0x76, KeyEvent.KEYCODE_F7); // vk_f7 202 keymap.put(0x76, vt320.KEY_F7); // vk_f7
207 keymap.put(0x77, KeyEvent.KEYCODE_F8); // vk_f8 203 keymap.put(0x77, vt320.KEY_F8); // vk_f8
208 keymap.put(0x78, KeyEvent.KEYCODE_F9); // vk_f9 204 keymap.put(0x78, vt320.KEY_F9); // vk_f9
209 keymap.put(0x79, KeyEvent.KEYCODE_F10); // vk_f10 205 keymap.put(0x79, vt320.KEY_F10); // vk_f10
210 keymap.put(0x7a, KeyEvent.KEYCODE_F11); // vk_f11 206 keymap.put(0x7a, vt320.KEY_F11); // vk_f11
211 keymap.put(0x7b, KeyEvent.KEYCODE_F12); // vk_f12 207 keymap.put(0x7b, vt320.KEY_F12); // vk_f12
212 // bind to the monitor service 208 // bind to the monitor service
213 Intent intent = new Intent("com.five_ten_sg.connectbot.monitor.MonitorService"); 209 Intent intent = new Intent("com.five_ten_sg.connectbot.monitor.MonitorService");
214 parent.bindService(intent, monitor_connection, Context.BIND_AUTO_CREATE); 210 parent.bindService(intent, monitor_connection, Context.BIND_AUTO_CREATE);
215 Log.i(TAG, "constructor"); 211 Log.i(TAG, "constructor");
216 } 212 }
398 } 394 }
399 395
400 public synchronized void depress(int vk_key) { 396 public synchronized void depress(int vk_key) {
401 Log.i(TAG, String.format("depress() %d", vk_key)); 397 Log.i(TAG, String.format("depress() %d", vk_key));
402 Integer x = keymap.get(new Integer(vk_key)); 398 Integer x = keymap.get(new Integer(vk_key));
403 399 if (x != null) buffer.keyPressed(x, ' ', 0);
404 if (x != null) {
405 KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, x.intValue());
406 keyListener.onKey(view, event.getKeyCode(), event);
407 }
408 } 400 }
409 } 401 }