forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DefinitelyTyped#2779 from rcchen/master
Add typings for Keypress v2.0.3
- Loading branch information
Showing
3 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/// <reference path="keypress.d.ts"/> | ||
|
||
module KeypressComboTests { | ||
var listener = new window.keypress.Listener(); | ||
|
||
var copyCombo = <Keypress.Combo>{ | ||
keys: "cmd c", | ||
on_keydown: () => { | ||
console.log("Key down"); | ||
}, | ||
on_keyup: () => { | ||
console.log("Key up"); | ||
}, | ||
on_release: () => { | ||
console.log("Released"); | ||
}, | ||
prevent_default: true, | ||
prevent_repeat: false, | ||
is_unordered: true, | ||
is_counting: false, | ||
is_exclusive: false, | ||
is_sequence: true, | ||
is_solitary: true | ||
}; | ||
|
||
var pasteCombo = <Keypress.Combo>{ | ||
keys: "ctrl v", | ||
on_keydown: () => { | ||
console.log("Paste"); | ||
}, | ||
prevent_default: true, | ||
prevent_repeat: true, | ||
is_exclusive: true | ||
}; | ||
|
||
listener.register_combo(copyCombo); | ||
listener.unregister_combo("cmd c"); | ||
|
||
listener.register_many([copyCombo, pasteCombo]); | ||
listener.stop_listening(); | ||
listener.listen(); | ||
listener.unregister_many(["cmd c", "cmd v"]); | ||
|
||
listener.reset(); | ||
} | ||
|
||
module KeypressBindingTests { | ||
var element = document.createElement('div'); | ||
var defaults = <Keypress.ListenerDefaults>{ | ||
prevent_default: true, | ||
prevent_repeat: true, | ||
is_unordered: true, | ||
is_counting: false, | ||
is_exclusive: false, | ||
is_solitary: false, | ||
is_sequence: false | ||
}; | ||
var listener = new window.keypress.Listener(element); | ||
listener = new window.keypress.Listener(element, defaults); | ||
listener.reset(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Type definitions for Keypress v2.0.3 | ||
// Project: https://github.com/dmauro/Keypress/ | ||
// Definitions by: Roger Chen <https://github.com/rcchen> | ||
// Definitions: https://github.com/borisyankov/DefinitelyTyped | ||
|
||
// A keyboard input capturing utility in which any key can be a modifier key. | ||
declare module Keypress { | ||
|
||
interface ListenerDefaults { | ||
keys: string; | ||
prevent_default: boolean; | ||
prevent_repeat: boolean; | ||
is_unordered: boolean; | ||
is_counting: boolean; | ||
is_exclusive: boolean; | ||
is_solitary: boolean; | ||
is_sequence: boolean; | ||
} | ||
|
||
interface Combo { | ||
keys: string; | ||
on_keydown: () => any; | ||
on_keyup: () => any; | ||
on_release: () => any; | ||
this: Element; | ||
prevent_default: boolean; | ||
prevent_repeat: boolean; | ||
is_unordered: boolean; | ||
is_counting: boolean; | ||
is_exclusive: boolean; | ||
is_sequence: boolean; | ||
is_solitary: boolean; | ||
} | ||
|
||
interface Listener { | ||
new(element: Element, defaults: ListenerDefaults): Listener; | ||
new(element: Element): Listener; | ||
new(): Listener; | ||
simple_combo(keys: string, on_keydown_callback: () => any): void; | ||
counting_combo(keys: string, on_count_callback: () => any): void; | ||
sequence_combo(keys: string, callback: () => any): void; | ||
register_combo(combo: Combo): void; | ||
unregister_combo(combo: Combo): void; | ||
unregister_combo(keys: string): void; | ||
register_many(combos: Combo[]): void; | ||
unregister_many(combos: Combo[]): void; | ||
unregister_many(keys: string[]): void; | ||
get_registered_combos(): Combo[]; | ||
reset(): void; | ||
listen(): void; | ||
stop_listening(): void; | ||
} | ||
|
||
interface Keypress { | ||
Listener: Listener; | ||
} | ||
} | ||
|
||
interface Window { | ||
keypress: Keypress.Keypress; | ||
} |