2 * (C) Copyright 2008 Jeremy Maitin-Shepard
4 * Use, modification, and distribution are subject to the terms specified in the
8 require("keyboard.js");
10 var global_overlay_keymap
= new keymap();
12 function global_overlay_keymap_handler(window
, ctx
, true_event
) {
13 var binding
= lookup_key_binding(global_overlay_keymap
, ctx
.event
);
16 if (!binding
.fallthrough
)
18 true_event
.preventDefault();
19 true_event
.stopPropagation();
23 call_interactively(ctx
, binding
.command
);
28 define_global_mode("global_overlay_keymap_mode",
30 add_hook("key_press_hook", global_overlay_keymap_handler
);
33 remove_hook("key_press_hook", global_overlay_keymap_handler
);
36 function define_key_alias(typed_key
, generated_key
) {
37 typed_key
= kbd(typed_key
);
38 generated_key
= kbd(generated_key
);
39 var formatted
= format_key_spec(generated_key
[0]);
40 var name
= "generate-key-event:" + formatted
;
42 "Generate a fake key press event for the key: " + formatted
,
44 send_key_as_event(I
.window
, I
.buffer
.focused_element
, generated_key
);
46 define_key(global_overlay_keymap
, typed_key
, name
);
47 global_overlay_keymap_mode(true);
49 ignore_function_for_get_caller_source_code_reference("define_key_alias");
52 function define_sticky_modifier(typed_key
, modifiers
) {
53 typed_key
= kbd(typed_key
);
55 for (var i
= 0; i
< modifier_names
.length
; ++i
)
57 if (modifiers
& (1 << i
)) {
58 if (mod_str
.length
> 0)
59 mod_str
= mod_str
+ "-";
60 mod_str
= mod_str
+ modifier_names
[i
];
63 if (mod_str
.length
== 0)
64 throw new Error("Invalid modifiers: " + modifiers
);
65 var name
= "sticky-modifiers:" + mod_str
;
66 interactive(name
, "Set sticky modifiers: " + mod_str
, function (I
) {
67 I
.sticky_modifiers
|= modifiers
;
69 define_key(global_overlay_keymap
, typed_key
, name
);
70 global_overlay_keymap_mode(true);
72 ignore_function_for_get_caller_source_code_reference("define_sticky_modifier");