Last active
September 13, 2019 23:20
-
-
Save katsaii/e65f234c5c3293e9f2be875b435514a5 to your computer and use it in GitHub Desktop.
A script for enabling/disabling keyboard input in GameMaker.
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
gml_pragma("global", @' | |
global.keyboard_mapping = undefined;'); | |
/// @desc Disables/enables the keyboard. | |
/// @param enable {Bool} Whether to enable the keyboard. | |
/// @author Kat @katsaii | |
if (argument0) { | |
// revert remaps | |
if (global.keyboard_mapping != undefined) { | |
var maps = global.keyboard_mapping; | |
var key = ds_map_find_first(maps); | |
repeat (ds_map_size(maps)) { | |
keyboard_set_map(key, maps[? key]); | |
// goto next key | |
key = ds_map_find_next(maps, key); | |
} | |
ds_map_destroy(maps); | |
global.keyboard_mapping = undefined; | |
} | |
} else { | |
// unmap keyboard keys | |
if (global.keyboard_mapping == undefined) { | |
var maps = ds_map_create(); | |
for (var key = 0; key < 255; key++) { | |
switch (key) { | |
case vk_anykey: | |
case vk_nokey: | |
// blacklisted keys | |
continue; | |
} | |
maps[? key] = keyboard_get_map(key); | |
keyboard_clear(key); | |
keyboard_set_map(key, vk_nokey); | |
} | |
global.keyboard_mapping = maps; | |
} | |
} |
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
/// @desc Returns whether the keyboard is enabled. | |
/// @author Kat @katsaii | |
return global.keyboard_mapping == undefined; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment