forked from CCBlueX/java-cef
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyboardHandler.java
More file actions
52 lines (49 loc) · 2.21 KB
/
KeyboardHandler.java
File metadata and controls
52 lines (49 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
package tests.detailed.handler;
import org.cef.browser.CefBrowser;
import org.cef.handler.CefKeyboardHandlerAdapter;
public class KeyboardHandler extends CefKeyboardHandlerAdapter {
@Override
public boolean onKeyEvent(CefBrowser browser, CefKeyEvent event) {
if (!event.focus_on_editable_field && event.windows_key_code == 0x20) {
// Special handling for the space character when an input element does not
// have focus. Handling the event in OnPreKeyEvent() keeps the event from
// being processed in the renderer. If we instead handled the event in the
// OnKeyEvent() method the space key would cause the window to scroll in
// addition to showing the alert box.
if (event.type == CefKeyEvent.EventType.KEYEVENT_RAWKEYDOWN) {
browser.executeJavaScript("alert('You pressed the space bar!');", "", 0);
}
return true;
} else if (event.type == CefKeyEvent.EventType.KEYEVENT_RAWKEYDOWN && event.is_system_key) {
// CMD+[key] is not working on a Mac.
// This switch statement delegates the common keyboard shortcuts to the browser
switch (event.unmodified_character) {
case 'a':
browser.getFocusedFrame().selectAll();
break;
case 'c':
browser.getFocusedFrame().copy();
break;
case 'v':
browser.getFocusedFrame().paste();
break;
case 'x':
browser.getFocusedFrame().cut();
break;
case 'z':
browser.getFocusedFrame().undo();
break;
case 'Z':
browser.getFocusedFrame().redo();
break;
default:
return false;
}
return true;
}
return false;
}
}