Jump to content
Chainsawkitten

Disable F1, Alt+Enter and F12

Recommended Posts

I made this for Clandestinity of Elsie, which released a year ago, and finally thought "hey, maybe someone else could use it too".

 

What?

This DLL and script disables F1 (menu where you can configure controls), F12 (resets the game) and Alt+Enter (switch between fullscreen and windowed mode).

 

You can choose which keys you want to disable.

 

How?

By setting 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.

 

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 it really shouldn't be part of any final release.

 

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

All the script really does is simply call the DLL, which registers the hook.

#==============================================================================
# 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)

Example Project (and DLL)

Source

 

Requirements

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.

 

License

Do whatever you want to. Full text.

Edited by Chainsawkitten
Updated download link

Share this post


Link to post
Share on other sites

I have seen several attempts at accomplishing this (as you correctly note, the f12 button is inescapably annoying).

 

Are there any implications on performance or the system at all for those of us who not well versed in C?'

 

Also, your example project link is "in violation" of Googles terms and does not work.

Edited by Dymdez

Share this post


Link to post
Share on other sites

I have seen several attempts at accomplishing this (as you correctly note, the f12 button is inescapably annoying).

 

Are there any implications on performance or the system at all for those of us who not well versed in C?'

The performance costs consists of both the interrupt and the code executed in the hook.

 

The code executed in the hook I measured to take 0.026000s for 10000 loops => average of 0.0026ms. (Note: I didn't subtract the cost of the for-loop itself so real cost should be a little lower). On AMD Athlon II X3 450 (3.2 GHz).

 

The interrupt itself is system-dependent and I'm not sure how to measure that. Here's some info on the performance on context switching. According to OSNews, the performance cost of a context switch (cause by an interrupt) on a Pentium 4 (2.8 GHz) is 995 ns = 0.000995ms.

 

We get an interrupt when the player presses any key so we should only really get one per frame (max), which means a maximum performance loss of 0.000995ms + 0.0026ms = 0.003595ms per frame. That's 0.003595/(1000/60) = 0.02157% of your per-frame budget on 60 fps. In other words, the performance loss should be negligible.

 

Also, your example project link is "in violation" of Googles terms and does not work.

That's really annoying. Google thinks it's a virus for some reason.

 

Here's a VirusTotal scan of the zip. (Site that uses 53 different anti-virus programs to scan it). The detection rate is 2/53. For reference, RPGVXAce.exe has 2/57 (it was scanned 2 months ago, when they apparently used 4 more programs).

 

I switched to Dropbox, which doesn't seem to complain. If you don't trust me, you can always compile from source.

 

For reference, we released our game on Steam with this and haven't had any players complain about problems with their Anti-Virus software detecting it (not sure how common Cyren and F-Prot are, it's the first I've heard of them).

Share this post


Link to post
Share on other sites

Well, I think this is a hugely important script, to be honest.  It should have far more attention.  My only fear is the requirements for end-users to have certain files; this is troublesome because it's never a good idea to make it harder to play a game, as you know! Is there a way around that? To compile it with the game? Or is this a noob-nonsense question?

 

Also, could you link me to your game, sounds interesting. NVMD

 

going to test now and report back soon! :)

 

Edit: Oh yes, it works :)

Edited by Dymdez

Share this post


Link to post
Share on other sites

My only fear is the requirements for end-users to have certain files; this is troublesome because it's never a good idea to make it harder to play a game, as you know! Is there a way around that? To compile it with the game? Or is this a noob-nonsense question?

For us, it wasn't much of an issue, since we already needed to use an installer (for the non-Steam release) since we require XInput 1.3 to be installed (since we use that for gamepad input). Plus, Steam has a really easy, automated way to install the VC redistributables (XInput required some custom scripting).

 

I honestly don't know too much about MSVC. As far as I know, you'll need the redistributables but maybe there's some way to statically link all you need. If you don't want to have to install the redistributables, you could use a different compiler, eg. MinGW. I usually use CMake (and MinGW) but since this was all Windows specific anyhow I figured I might as well go with Visual Studio.

 

 

Also, could you link me to your game, sounds interesting.

Clandestinity of Elsie. It's dirt cheap for another hour or so before the Steam summer sale ends. Edited by Chainsawkitten

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted