MCPcopy Create free account
hub / github.com/candybox2/candybox2.github.io / execute

Function execute

code/main/Keyboard.ts:9–48  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7 }
8
9 export function execute(): void{
10 // Handle keydown events
11 $(document).keydown(function(event){
12 // Can we use hotkeys ?
13 var canUseHotkeys: boolean = getCanUseHotkeys();
14
15 // Handle hotkeys
16 for(var keyString in game.getHotkeys()){
17 if(event.which == game.getHotkeys()[keyString].getKey()){
18 game.getHotkeys()[keyString].setPressed(true);
19 if(canUseHotkeys){
20 if(game.getHotkeys()[keyString].getCallbackCollection() != null) game.getHotkeys()[keyString].getCallbackCollection().fire();
21 event.preventDefault();
22 return false;
23 }
24 }
25 }
26
27 // Handle special hotkeys
28 if(canUseHotkeys){
29 for(var i = 0; i < game.getSpecialHotkeys().length; i++){
30 if(event.which == game.getSpecialHotkeys()[i].getKey()){
31 if(game.getSpecialHotkeys()[i].getCallbackCollection() != null) game.getSpecialHotkeys()[i].getCallbackCollection().fire();
32 event.preventDefault();
33 return false;
34 }
35 }
36 }
37 });
38
39 // Handle keyup events
40 $(document).keyup(function(event){
41 // Handle hotkeys
42 for(var keyString in game.getHotkeys()){
43 if(event.which == game.getHotkeys()[keyString].getKey()){
44 game.getHotkeys()[keyString].setPressed(false);
45 }
46 }
47 });
48 }
49
50 function getCanUseHotkeys(): boolean{
51 if($(':focus').hasClass("noHotkeys"))

Callers

nothing calls this directly

Calls 11

$Function · 0.85
getCanUseHotkeysFunction · 0.85
keydownMethod · 0.80
getHotkeysMethod · 0.80
getKeyMethod · 0.80
setPressedMethod · 0.80
preventDefaultMethod · 0.80
getSpecialHotkeysMethod · 0.80
keyupMethod · 0.80
fireMethod · 0.65
getCallbackCollectionMethod · 0.45

Tested by

no test coverage detected