07-14-2019, 03:56 AM
Disable F1, Alt+Enter and F12
by Chainsawkitten
Original thread found by DerVVulfman at RPGMaker Central
by Chainsawkitten
Original thread found by DerVVulfman at RPGMaker Central
Introduction
"I made this for Clandestinity of Elsie, which released a year ago, and finally thought "hey, maybe someone else could use it too"." - Chainsawkitten (June 26, 2016)
This script, combined with an accompanying DLL file, allows you to disable certain keys in your RPG Maker game. How? It sets a hook for key input which catches those keypresses, making sure the game never receives them (and thus those things don't trigger). Since RPG Maker also checks keyboard status directly for F12, we also fake that it isn't pressed by using 'SetKeyboardState'.
Features
- Allows the user to disable the [F1] key
- Allows the user to disable the [Alt]+[Enter] combination which toggles fullscreen/window mode
- Allows the user to disable the [F12] key (RPGMaker VXAce Only)
Limitations
Since the hook completely devours that input, you won't be able to use F1, F12 or Alt+Enter for anything else. (If you want to disable a key so you could use it for something else, that's not too difficult. Just change messageHandling so it stores that the key has been pressed and then implement a function to get that value (which also clears it). Anyone with some basic C knowledge should be able to do that.)
Why Disable F1?
The default control settings suck so we decided to do our own (with support for other keys and "better" gamepad (subjective, we used XInput)). If you don't implement your own settings to replace them, you probably shouldn't disable it.
Set DISABLE_F1 = 0 if you don't want to disable it.
Why Disable F12?
F12 may be useful for debugging but some scripters and users find it an annoyance when some players wish to reset their game and find a 'stack error' if some script didn't alias code properly (ie they generated an F12 bug).
Set DISABLE_F12 = 0 if you don't want to disable it.
Why disable Alt+Enter?
Because we wanted to use another (better) fullscreen implementation.
Set DISABLE_ALT_ENTER = 0 if you don't want to disable it.
Script
Actually... no. Surprisingly simple to use.
Script
All the script really does is simply call the DLL, which registers the hook. The code assumes your project has folders for Data, Graphics, Audio and System (a new folder) in your project's root.
The Script
Code:
#==============================================================================
# Chainsawkitten's Disable F1, Alt+Enter, F12 v1.1
#------------------------------------------------------------------------------
# Disable the use of F1, Alt+Enter and F12 by registering a hook which consumes
# keypress events as well as setting the keyboard state.
#==============================================================================
module CskDisable
# Whether to disable F1. 0 = enable, 1 = disable.
DISABLE_F1 = 1
# Whether to disable F12. 0 = enable, 1 = disable.
DISABLE_F12 = 1
# Whether to disable Alt+Enter. 0 = enable, 1 = disable.
DISABLE_ALT_ENTER = 1
end
Win32API.new("System/F1AltEnterF12", "hook", "III", "").call(
CskDisable::DISABLE_F1,
CskDisable::DISABLE_F12,
CskDisable::DISABLE_ALT_ENTER)
Required DLL
Attachment found here:
https://www.save-point.org/attachment.php?aid=1156
The source code for the DLL can be found HERE.
Instructions
Create a new folder in your project called 'System'. And in the system folder, paste a copy of the required DLL. After that, paste the above script in your Scripts Database, typically below Scene_Debug and above Main and configure in the CskDisable module as noted above.
Compatability
This can work with RPGMaker XP, VX and VXAce. However, only VXAce permits the F12 key to be blocked. The F12 feature is not blocked by this system for the older two engines.
Requirements
Besides the DLL above, this requires the Microsoft Visual C++ 2013 Redistributables (x86) to be installed. Your end-user will have to install it too. You can compile the DLL from source if you want a different vesion of MSVC or if you want to port it to MinGW or whatever. The project consists of a single .c file so that part shouldn't be much work. Other than that, I hardcoded in the wrangled function name of the hook-function "_messageHandling@12", you may have to change that if you use a different compiler.
Terms and Conditions
Do whatever you want to:
License
Open to read
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org>
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org>