Automatically reposition event target on focus in case browser automatically centers...
[guacamole.git] / src / main / webapp / scripts / interface.js
1
2 // UI Definition
3 var GuacamoleUI = {
4
5     /* Detection Constants */
6     
7     "LONG_PRESS_DETECT_TIMEOUT"     : 800, /* milliseconds */
8     "LONG_PRESS_MOVEMENT_THRESHOLD" : 10,  /* pixels */
9     "MENU_CLOSE_DETECT_TIMEOUT"     : 500, /* milliseconds */
10     "MENU_OPEN_DETECT_TIMEOUT"      : 325, /* milliseconds */
11     "KEYBOARD_AUTO_RESIZE_INTERVAL" : 30,  /* milliseconds */
12
13     /* Animation Constants */
14
15     "MENU_SHADE_STEPS"    : 10, /* frames */
16     "MENU_SHADE_INTERVAL" : 30, /* milliseconds */
17     "MENU_SHOW_STEPS"     : 5,  /* frames */
18     "MENU_SHOW_INTERVAL"  : 30, /* milliseconds */
19
20     /* OSK Mode Constants */
21     "OSK_MODE_NATIVE" : 1, /* "Show Keyboard" will show the platform's native OSK */
22     "OSK_MODE_GUAC"   : 2, /* "Show Keyboard" will show Guac's built-in OSK */
23
24     /* UI Elements */
25
26     "viewport"    : document.getElementById("viewportClone"),
27     "display"     : document.getElementById("display"),
28     "menu"        : document.getElementById("menu"),
29     "menuControl" : document.getElementById("menuControl"),
30     "touchMenu"   : document.getElementById("touchMenu"),
31     "logo"        : document.getElementById("status-logo"),
32     "eventTarget" : document.getElementById("eventTarget"),
33
34     "buttons": {
35
36         "showClipboard": document.getElementById("showClipboard"),
37         "showKeyboard" : document.getElementById("showKeyboard"),
38         "ctrlAltDelete": document.getElementById("ctrlAltDelete"),
39         "reconnect"    : document.getElementById("reconnect"),
40         "logout"       : document.getElementById("logout"),
41
42         "touchShowClipboard" : document.getElementById("touchShowClipboard"),
43         "touchShowKeyboard"  : document.getElementById("touchShowKeyboard"),
44         "touchLogout"        : document.getElementById("touchLogout")
45
46     },
47
48     "containers": {
49         "state"    : document.getElementById("statusDialog"),
50         "clipboard": document.getElementById("clipboardDiv"),
51         "keyboard" : document.getElementById("keyboardContainer")
52     },
53     
54     "state"     : document.getElementById("statusText"),
55     "clipboard" : document.getElementById("clipboard")
56
57 };
58
59 // Constant UI initialization and behavior
60 (function() {
61
62     var menu_shaded = false;
63
64     var shade_interval = null;
65     var show_interval = null;
66
67     // Cache error image (might not be available when error occurs)
68     var guacErrorImage = new Image();
69     guacErrorImage.src = "images/noguacamole-logo-24.png";
70
71     // Function for adding a class to an element
72     var addClass;
73
74     // Function for removing a class from an element
75     var removeClass;
76
77     // If Node.classList is supported, implement addClass/removeClass using that
78     if (Node.classList) {
79
80         addClass = function(element, classname) {
81             element.classList.add(classname);
82         };
83         
84         removeClass = function(element, classname) {
85             element.classList.remove(classname);
86         };
87         
88     }
89
90     // Otherwise, implement own
91     else {
92
93         addClass = function(element, classname) {
94
95             // Simply add new class
96             element.className += " " + classname;
97
98         };
99         
100         removeClass = function(element, classname) {
101
102             // Filter out classes with given name
103             element.className = element.className.replace(/([^ ]+)[ ]*/g,
104                 function(match, testClassname, spaces, offset, string) {
105
106                     // If same class, remove
107                     if (testClassname == classname)
108                         return "";
109
110                     // Otherwise, allow
111                     return match;
112                     
113                 }
114             );
115
116         };
117         
118     }
119
120
121     GuacamoleUI.hideStatus = function() {
122         removeClass(document.body, "guac-error");
123         GuacamoleUI.containers.state.style.visibility = "hidden";
124         GuacamoleUI.display.style.opacity = "1";
125     };
126     
127     GuacamoleUI.showStatus = function(text) {
128         removeClass(document.body, "guac-error");
129         GuacamoleUI.containers.state.style.visibility = "visible";
130         GuacamoleUI.state.textContent = text;
131         GuacamoleUI.display.style.opacity = "1";
132     };
133     
134     GuacamoleUI.showError = function(error) {
135         addClass(document.body, "guac-error");
136         GuacamoleUI.state.textContent = error;
137         GuacamoleUI.display.style.opacity = "0.1";
138     };
139
140     GuacamoleUI.hideTouchMenu = function() {
141         GuacamoleUI.touchMenu.style.visibility = "hidden";
142     };
143     
144     GuacamoleUI.showTouchMenu = function() {
145         
146         GuacamoleUI.touchMenu.style.left =
147             ((GuacamoleUI.viewport.offsetWidth - GuacamoleUI.touchMenu.offsetWidth) / 2
148             + window.pageXOffset)
149             + "px";
150
151         GuacamoleUI.touchMenu.style.top =
152             ((GuacamoleUI.viewport.offsetHeight - GuacamoleUI.touchMenu.offsetHeight) / 2
153             + window.pageYOffset)
154             + "px";
155
156         GuacamoleUI.touchMenu.style.visibility = "visible";
157         
158     };
159
160     GuacamoleUI.shadeMenu = function() {
161
162         if (!menu_shaded) {
163
164             var step = Math.floor(GuacamoleUI.menu.offsetHeight / GuacamoleUI.MENU_SHADE_STEPS) + 1;
165             var offset = 0;
166             menu_shaded = true;
167
168             window.clearInterval(show_interval);
169             shade_interval = window.setInterval(function() {
170
171                 offset -= step;
172
173                 GuacamoleUI.menu.style.transform =
174                 GuacamoleUI.menu.style.WebkitTransform =
175                 GuacamoleUI.menu.style.MozTransform =
176                 GuacamoleUI.menu.style.OTransform =
177                 GuacamoleUI.menu.style.msTransform =
178
179                     "translateY(" + offset + "px)";
180
181                 if (offset <= -GuacamoleUI.menu.offsetHeight) {
182                     window.clearInterval(shade_interval);
183                     GuacamoleUI.menu.style.visiblity = "hidden";
184                 }
185
186             }, GuacamoleUI.MENU_SHADE_INTERVAL);
187         }
188
189     };
190
191     GuacamoleUI.showMenu = function() {
192
193         if (menu_shaded) {
194
195             var step = Math.floor(GuacamoleUI.menu.offsetHeight / GuacamoleUI.MENU_SHOW_STEPS) + 1;
196             var offset = -GuacamoleUI.menu.offsetHeight;
197             menu_shaded = false;
198             GuacamoleUI.menu.style.visiblity = "";
199
200             window.clearInterval(shade_interval);
201             show_interval = window.setInterval(function() {
202
203                 offset += step;
204
205                 if (offset >= 0) {
206                     offset = 0;
207                     window.clearInterval(show_interval);
208                 }
209
210                 GuacamoleUI.menu.style.transform =
211                 GuacamoleUI.menu.style.WebkitTransform =
212                 GuacamoleUI.menu.style.MozTransform =
213                 GuacamoleUI.menu.style.OTransform =
214                 GuacamoleUI.menu.style.msTransform =
215
216                     "translateY(" + offset + "px)";
217
218             }, GuacamoleUI.MENU_SHOW_INTERVAL);
219         }
220
221     };
222
223     // Show/Hide clipboard
224     GuacamoleUI.buttons.showClipboard.onclick = function() {
225
226         var displayed = GuacamoleUI.containers.clipboard.style.display;
227         if (displayed != "block") {
228             GuacamoleUI.containers.clipboard.style.display = "block";
229             GuacamoleUI.buttons.showClipboard.innerHTML = "Hide Clipboard";
230         }
231         else {
232             GuacamoleUI.containers.clipboard.style.display = "none";
233             GuacamoleUI.buttons.showClipboard.innerHTML = "Show Clipboard";
234             GuacamoleUI.clipboard.onchange();
235         }
236
237     };
238
239     GuacamoleUI.buttons.touchShowClipboard.onclick = function() {
240         // FIXME: Implement
241         alert("Not yet implemented... Sorry.");
242     };
243
244     // Show/Hide keyboard
245     var keyboardResizeInterval = null;
246     GuacamoleUI.buttons.showKeyboard.onclick = function() {
247
248         // If Guac OSK shown, hide it.
249         var displayed = GuacamoleUI.containers.keyboard.style.display;
250         if (displayed == "block") {
251             GuacamoleUI.containers.keyboard.style.display = "none";
252             GuacamoleUI.buttons.showKeyboard.textContent = "Show Keyboard";
253
254             window.onresize = null;
255             window.clearInterval(keyboardResizeInterval);
256         }
257
258         // Otherwise, show it
259         else {
260
261             // Ensure event target is NOT focused if we are using the Guac OSK.
262             GuacamoleUI.eventTarget.blur();
263
264             GuacamoleUI.containers.keyboard.style.display = "block";
265             GuacamoleUI.buttons.showKeyboard.textContent = "Hide Keyboard";
266
267             // Automatically update size
268             window.onresize = updateKeyboardSize;
269             keyboardResizeInterval = window.setInterval(updateKeyboardSize,
270                 GuacamoleUI.KEYBOARD_AUTO_RESIZE_INTERVAL);
271
272             updateKeyboardSize();
273
274         }
275
276     };
277
278     // Touch-specific keyboard show
279     GuacamoleUI.buttons.touchShowKeyboard.ontouchstart = 
280     GuacamoleUI.buttons.touchShowKeyboard.onclick = 
281         function(e) {
282
283             // Center event target in case browser automatically centers
284             // input fields on focus.
285             GuacamoleUI.eventTarget.style.left =
286                 (window.pageXOffset + GuacamoleUI.viewport.offsetWidth / 2) + "px";
287
288             GuacamoleUI.eventTarget.style.top =
289                 (window.pageYOffset + GuacamoleUI.viewport.offsetHeight / 2) + "px";
290
291             GuacamoleUI.eventTarget.focus();
292             GuacamoleUI.hideTouchMenu();
293             e.preventDefault();
294         };
295
296     // Logout
297     GuacamoleUI.buttons.logout.onclick =
298     GuacamoleUI.buttons.touchLogout.onclick =
299         function() {
300             window.location.href = "logout";
301         };
302
303     // Timeouts for detecting if users wants menu to open or close
304     var detectMenuOpenTimeout = null;
305     var detectMenuCloseTimeout = null;
306
307     // Clear detection timeouts
308     GuacamoleUI.resetMenuDetect = function() {
309
310         if (detectMenuOpenTimeout != null) {
311             window.clearTimeout(detectMenuOpenTimeout);
312             detectMenuOpenTimeout = null;
313         }
314
315         if (detectMenuCloseTimeout != null) {
316             window.clearTimeout(detectMenuCloseTimeout);
317             detectMenuCloseTimeout = null;
318         }
319
320     };
321
322     // Initiate detection of menu open action. If not canceled through some
323     // user event, menu will open.
324     GuacamoleUI.startMenuOpenDetect = function() {
325
326         if (!detectMenuOpenTimeout) {
327
328             // Clear detection state
329             GuacamoleUI.resetMenuDetect();
330
331             // Wait and then show menu
332             detectMenuOpenTimeout = window.setTimeout(function() {
333
334                 // If menu opened via mouse, do not show native OSK
335                 GuacamoleUI.oskMode = GuacamoleUI.OSK_MODE_GUAC;
336
337                 GuacamoleUI.showMenu();
338                 detectMenuOpenTimeout = null;
339             }, GuacamoleUI.MENU_OPEN_DETECT_TIMEOUT);
340
341         }
342
343     };
344
345     // Initiate detection of menu close action. If not canceled through some
346     // user mouse event, menu will close.
347     GuacamoleUI.startMenuCloseDetect = function() {
348
349         if (!detectMenuCloseTimeout) {
350
351             // Clear detection state
352             GuacamoleUI.resetMenuDetect();
353
354             // Wait and then shade menu
355             detectMenuCloseTimeout = window.setTimeout(function() {
356                 GuacamoleUI.shadeMenu();
357                 detectMenuCloseTimeout = null;
358             }, GuacamoleUI.MENU_CLOSE_DETECT_TIMEOUT);
359
360         }
361
362     };
363
364     // Show menu if mouseover any part of menu
365     GuacamoleUI.menu.addEventListener('mouseover', GuacamoleUI.showMenu, true);
366
367     // Stop detecting menu state change intents if mouse is over menu
368     GuacamoleUI.menu.addEventListener('mouseover', GuacamoleUI.resetMenuDetect, true);
369
370     // When mouse hovers over top of screen, start detection of intent to open menu
371     GuacamoleUI.menuControl.addEventListener('mousemove', GuacamoleUI.startMenuOpenDetect, true);
372
373     var long_press_start_x = 0;
374     var long_press_start_y = 0;
375     var menuShowLongPressTimeout = null;
376
377     GuacamoleUI.startLongPressDetect = function() {
378
379         if (!menuShowLongPressTimeout) {
380
381             menuShowLongPressTimeout = window.setTimeout(function() {
382                 
383                 menuShowLongPressTimeout = null;
384
385                 // Assume native OSK if menu shown via long-press
386                 GuacamoleUI.oskMode = GuacamoleUI.OSK_MODE_NATIVE;
387                 GuacamoleUI.showTouchMenu();
388
389             }, GuacamoleUI.LONG_PRESS_DETECT_TIMEOUT);
390
391         }
392     };
393
394     GuacamoleUI.stopLongPressDetect = function() {
395         window.clearTimeout(menuShowLongPressTimeout);
396         menuShowLongPressTimeout = null;
397     };
398
399     // Detect long-press at bottom of screen
400     GuacamoleUI.display.addEventListener('touchstart', function(e) {
401         
402         // Close menu if shown
403         GuacamoleUI.shadeMenu();
404         GuacamoleUI.hideTouchMenu();
405         
406         // Record touch location
407         if (e.touches.length == 1) {
408             var touch = e.touches[0];
409             long_press_start_x = touch.screenX;
410             long_press_start_y = touch.screenY;
411         }
412         
413         // Start detection
414         GuacamoleUI.startLongPressDetect();
415         
416     }, true);
417
418     // Stop detection if touch moves significantly
419     GuacamoleUI.display.addEventListener('touchmove', function(e) {
420         
421         // If touch distance from start exceeds threshold, cancel long press
422         var touch = e.touches[0];
423         if (Math.abs(touch.screenX - long_press_start_x) >= GuacamoleUI.LONG_PRESS_MOVEMENT_THRESHOLD
424             || Math.abs(touch.screenY - long_press_start_y) >= GuacamoleUI.LONG_PRESS_MOVEMENT_THRESHOLD)
425             GuacamoleUI.stopLongPressDetect();
426         
427     }, true);
428
429     // Stop detection if press stops
430     GuacamoleUI.display.addEventListener('touchend', GuacamoleUI.stopLongPressDetect, true);
431
432     // Close menu on mouse movement
433     GuacamoleUI.display.addEventListener('mousemove', GuacamoleUI.startMenuCloseDetect, true);
434     GuacamoleUI.display.addEventListener('mousedown', GuacamoleUI.startMenuCloseDetect, true);
435
436     // Reconnect button
437     GuacamoleUI.buttons.reconnect.onclick = function() {
438         window.location.reload();
439     };
440
441     // On-screen keyboard
442     GuacamoleUI.keyboard = new Guacamole.OnScreenKeyboard("layouts/en-us-qwerty-mobile.xml");
443     GuacamoleUI.containers.keyboard.appendChild(GuacamoleUI.keyboard.getElement());
444
445     // Function for automatically updating keyboard size
446     var lastKeyboardWidth;
447     function updateKeyboardSize() {
448         var currentSize = GuacamoleUI.keyboard.getElement().offsetWidth;
449         if (lastKeyboardWidth != currentSize) {
450             GuacamoleUI.keyboard.resize(currentSize);
451             lastKeyboardWidth = currentSize;
452         }
453     };
454
455     // Turn off autocorrect and autocapitalization on eventTarget
456     GuacamoleUI.eventTarget.setAttribute("autocorrect", "off");
457     GuacamoleUI.eventTarget.setAttribute("autocapitalize", "off");
458
459     // Automatically reposition event target on scroll
460     window.addEventListener("scroll", function() {
461         GuacamoleUI.eventTarget.style.left = window.pageXOffset + "px";
462         GuacamoleUI.eventTarget.style.top = window.pageYOffset + "px";
463     });
464
465 })();
466
467 // Tie UI events / behavior to a specific Guacamole client
468 GuacamoleUI.attach = function(guac) {
469
470     var title_prefix = null;
471     var connection_name = "Guacamole"; 
472     
473     var guac_display = guac.getDisplay();
474
475     // Set document title appropriately, based on prefix and connection name
476     function updateTitle() {
477
478         // Use title prefix if present
479         if (title_prefix) {
480             
481             document.title = title_prefix;
482
483             // Include connection name, if present
484             if (connection_name)
485                 document.title += " " + connection_name;
486
487         }
488
489         // Otherwise, just set to connection name
490         else if (connection_name)
491             document.title = connection_name;
492
493     }
494
495     // When mouse enters display, start detection of intent to close menu
496     guac_display.addEventListener('mouseover', GuacamoleUI.startMenuCloseDetect, true);
497
498     guac_display.onclick = function(e) {
499         e.preventDefault();
500         return false;
501     };
502
503     // Mouse
504     var mouse = new Guacamole.Mouse(guac_display);
505     mouse.onmousedown = mouse.onmouseup = mouse.onmousemove =
506         function(mouseState) {
507        
508             // Determine mouse position within view
509             var mouse_view_x = mouseState.x + guac_display.offsetLeft - window.pageXOffset;
510             var mouse_view_y = mouseState.y + guac_display.offsetTop  - window.pageYOffset;
511
512             // Determine viewport dimensioins
513             var view_width  = GuacamoleUI.viewport.offsetWidth;
514             var view_height = GuacamoleUI.viewport.offsetHeight;
515
516             // Determine scroll amounts based on mouse position relative to document
517
518             var scroll_amount_x;
519             if (mouse_view_x > view_width)
520                 scroll_amount_x = mouse_view_x - view_width;
521             else if (mouse_view_x < 0)
522                 scroll_amount_x = mouse_view_x;
523             else
524                 scroll_amount_x = 0;
525
526             var scroll_amount_y;
527             if (mouse_view_y > view_height)
528                 scroll_amount_y = mouse_view_y - view_height;
529             else if (mouse_view_y < 0)
530                 scroll_amount_y = mouse_view_y;
531             else
532                 scroll_amount_y = 0;
533
534             // Scroll (if necessary) to keep mouse on screen.
535             window.scrollBy(scroll_amount_x, scroll_amount_y);
536        
537             // Send mouse event
538             guac.sendMouseState(mouseState);
539             
540         };
541
542     // Keyboard
543     var keyboard = new Guacamole.Keyboard(document);
544
545     // Monitor whether the event target is focused
546     var eventTargetFocused = false;
547
548     // Save length for calculation of changed value
549     var currentLength = GuacamoleUI.eventTarget.value.length;
550
551     GuacamoleUI.eventTarget.onfocus = function() {
552         eventTargetFocused = true;
553         GuacamoleUI.eventTarget.value = "";
554         currentLength = 0;
555     };
556
557     GuacamoleUI.eventTarget.onblur = function() {
558         eventTargetFocused = false;
559     };
560
561     // If text is input directly into event target without typing (as with
562     // voice input, for example), type automatically.
563     GuacamoleUI.eventTarget.oninput = function(e) {
564
565         // Calculate current length and change in length
566         var oldLength = currentLength;
567         currentLength = GuacamoleUI.eventTarget.value.length;
568         
569         // If deleted or replaced text, ignore
570         if (currentLength <= oldLength)
571             return;
572
573         // Get changed text
574         var text = GuacamoleUI.eventTarget.value.substring(oldLength);
575
576         // Send each character
577         for (var i=0; i<text.length; i++) {
578
579             // Get char code
580             var charCode = text.charCodeAt(i);
581
582             // Convert to keysym
583             var keysym = 0x003F; // Default to a question mark
584             if (charCode >= 0x0000 && charCode <= 0x00FF)
585                 keysym = charCode;
586             else if (charCode >= 0x0100 && charCode <= 0x10FFFF)
587                 keysym = 0x01000000 | charCode;
588
589             // Send keysym only if not already pressed
590             if (!keyboard.pressed[keysym]) {
591
592                 // Press and release key
593                 guac.sendKeyEvent(1, keysym);
594                 guac.sendKeyEvent(0, keysym);
595
596             }
597
598         }
599
600     }
601
602     function isTypableCharacter(keysym) {
603         return (keysym & 0xFFFF00) != 0xFF00;
604     }
605
606     function disableKeyboard() {
607         keyboard.onkeydown = null;
608         keyboard.onkeyup = null;
609     }
610
611     function enableKeyboard() {
612
613         keyboard.onkeydown = function (keysym) {
614             guac.sendKeyEvent(1, keysym);
615             return eventTargetFocused && isTypableCharacter(keysym);
616         };
617
618         keyboard.onkeyup = function (keysym) {
619             guac.sendKeyEvent(0, keysym);
620             return eventTargetFocused && isTypableCharacter(keysym);
621         };
622
623     }
624
625     // Enable keyboard by default
626     enableKeyboard();
627
628     // Handle client state change
629     guac.onstatechange = function(clientState) {
630
631         switch (clientState) {
632
633             // Idle
634             case 0:
635                 GuacamoleUI.showStatus("Idle.");
636                 title_prefix = "[Idle]";
637                 break;
638
639             // Connecting
640             case 1:
641                 GuacamoleUI.shadeMenu();
642                 GuacamoleUI.showStatus("Connecting...");
643                 title_prefix = "[Connecting...]";
644                 break;
645
646             // Connected + waiting
647             case 2:
648                 GuacamoleUI.showStatus("Connected, waiting for first update...");
649                 title_prefix = "[Waiting...]";
650                 break;
651
652             // Connected
653             case 3:
654                 GuacamoleUI.hideStatus();
655                 title_prefix = null;
656                 break;
657
658             // Disconnecting
659             case 4:
660                 GuacamoleUI.showStatus("Disconnecting...");
661                 title_prefix = "[Disconnecting...]";
662                 break;
663
664             // Disconnected
665             case 5:
666                 GuacamoleUI.showStatus("Disconnected.");
667                 title_prefix = "[Disconnected]";
668                 break;
669
670             // Unknown status code
671             default:
672                 GuacamoleUI.showStatus("[UNKNOWN STATUS]");
673
674         }
675
676         updateTitle();
677     };
678
679     // Name instruction handler
680     guac.onname = function(name) {
681         connection_name = name;
682         updateTitle();
683     };
684
685     // Error handler
686     guac.onerror = function(error) {
687
688         // Disconnect, if connected
689         guac.disconnect();
690
691         // Display error message
692         GuacamoleUI.showError(error);
693         
694     };
695
696     // Disconnect on close
697     window.onunload = function() {
698         guac.disconnect();
699     };
700
701     // Handle clipboard events
702     GuacamoleUI.clipboard.onchange = function() {
703
704         var text = GuacamoleUI.clipboard.value;
705         guac.setClipboard(text);
706
707     };
708
709     // Ignore keypresses when clipboard is focused
710     GuacamoleUI.clipboard.onfocus = function() {
711         disableKeyboard();
712     };
713
714     // Capture keypresses when clipboard is not focused
715     GuacamoleUI.clipboard.onblur = function() {
716         enableKeyboard();
717     };
718
719     // Server copy handler
720     guac.onclipboard = function(data) {
721         GuacamoleUI.clipboard.value = data;
722     };
723
724     GuacamoleUI.keyboard.onkeydown = function(keysym) {
725         guac.sendKeyEvent(1, keysym);
726     };
727
728     GuacamoleUI.keyboard.onkeyup = function(keysym) {
729         guac.sendKeyEvent(0, keysym);
730     };
731
732     // Send Ctrl-Alt-Delete
733     GuacamoleUI.buttons.ctrlAltDelete.onclick = function() {
734
735         var KEYSYM_CTRL   = 0xFFE3;
736         var KEYSYM_ALT    = 0xFFE9;
737         var KEYSYM_DELETE = 0xFFFF;
738
739         guac.sendKeyEvent(1, KEYSYM_CTRL);
740         guac.sendKeyEvent(1, KEYSYM_ALT);
741         guac.sendKeyEvent(1, KEYSYM_DELETE);
742         guac.sendKeyEvent(0, KEYSYM_DELETE);
743         guac.sendKeyEvent(0, KEYSYM_ALT);
744         guac.sendKeyEvent(0, KEYSYM_CTRL);
745     };
746
747 };