HOW TO DISABLE ALT + ENTER?

Posts

Pages: 1
So I'm using this script that disables Alt + Enter, but in doing so disables any combination with the alt key -- including Alt + Tab and Alt + F4. Is it possible to ONLY disable Alt + Enter so that the others are still usable? Here's the code:

# Disable ALT-ENTER

module Input
class << self
unless self.method_defined?(:input_update)
alias_method(:input_update, :update)
end
def update
input_update
if Input.press?(Input::ALT)
#unless Keys.trigger?(Keys::F4)
keys = Win32API.new('user32', 'keybd_event', 'LLLL', '')
keys.call(18, 0, 2, 0)
#end
end
end
end
end
Not sure if this'll work, but you can try having an 'and' there.

like:
If Input.press?(Input::ALT) and (Input::Enter)

alternatively:
If Input.press?(Input::ALT) and If Input.press?(Input::Enter)

~Or something like that.
I tried that, but at that point it already triggers Alt + Enter. Doing that basically means "if Alt + Enter is already pressed". ^_^;

The script posted above basically disables any other key once Alt is pressed by filling it with a blank (keys.call(18, 0, 2, 0)).

I just don't have enough knowledge to figure out how to fix this so Alt + Tab and Alt + F4 can be used. :/
nhubi
Liberté, égalité, fraternité
11099
I'm curious, why are you disabling alt-enter?
I need to keep track of the game's resolution, so I changed Alt + Enter into a hotkey (F11).
nhubi
Liberté, égalité, fraternité
11099
Well that works as long as you tell the player. Otherwise you're just going to irritate them by changing the default they are accustomed to using. Players are, unfortunately, unforgiving (and yes, I speak as one).
I wouldn't recommend doing so. Honestly, unless you're using that key combo in your game there's no need to mess with it. Everyone and their dog knows to use for toggling fullscreen, so I don't see why you'd want to change something intuitive to something that isn't.
I would rather check whether the game is currently in fullscreen instead of changing the hotkey...
@Liberty: Because, like I said, I need to keep track of whether the game is in full screen or windowed mode for various reasons (one being that the game should start in the same resolution that it was closed in). If I keep Alt + Enter, I don't know of a way to keep track of it. :/ You can hit Alt + Enter at moments where the game isn't actually functioning, but it will still change resolution. Whereas if it's done through a hotkey that manually presses Alt + Enter through script, it can only be done when the game is active. Does that make sense? ^^;

@Cherry: Is there another way of checking what size the game is in?

As of right now F11 presses Alt + Enter indirectly and at the same time adjusts a variable to match the full screen / windowed mode.
There is one way to change the Alt-Enter combination to anything else, but is not by scripting...

Open your game's RGSSXXXX.dll (ie. RGSS102E.dll) in Resource Hacker. Then go to the resource named Accelerators. In there, look for this:

VK_RETURN, 2003, NOINVERT, ALT, VIRTKEY


Change VK_RETURN to something like VK_F13 (code for a F13 key exists, but there is no keyboard with F13 -and if there is one, just put something like F20, it exists too in code-).
Then, whenever you want to call for a regular Alt-Enter, you'll need something very similar to these lines.

keys = Win32API.new('user32', 'keybd_event', 'LLLL', '')

keys.call(18, 0, 2, 0)


Just Google how it works.
Function to check whether the game is in fullscreen:

def fullscreen?
# Get API functions and constants
_GetPrivateProfileStringA = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'L')
_FindWindow = Win32API.new('user32','FindWindow', %w(p p), 'L')
_GetWindowLong = Win32API.new('user32', 'GetWindowLong', %w(L l), 'L')
_GWL_STYLE = 16
_WS_POPUP = 0x80000000

# Get game title
game_name = "\0" * 256
_GetPrivateProfileString.call('Game', 'Title', '', game_name, 255, ".\\Game.ini")
game_name.delete!("\0")

# Find game window
window_handle = _FindWindow.call('RGSS Player', game_name)

# Get window style
window_style = _GetWindowLong.call(window_handle, _GWL_STYLE)

# If WS_POPUP style is set, the game is fullscreen
window_style & _WS_POPUP != 0
end

Disclaimer: I never used RMVX and I don't have any VX or VX Ace to test this with. I just wrote it out of my head using WinAPI and I cannot guarantee that it works.

@orochii: If you connect a Mac keyboard to a Windows PC, you can use F13-F15. There are also a few very very old keyboards with F13-F24, but I doubt anybody uses them anymore ^^ (Even Windows 8 uses F22-F24 for some internal trickery now) - However, I heard that Shift+Fx will create a F(x+12) keypress, but I never saw this actually happening... Still, it's better to use a key such as VK_EREOF ("Erase EOF key") which is most obscure.
@Cherry: Thank you! That looks really interesting. Would you happen to know if it can work for XP as well? I'm getting an RGSS error for the very first line. Possibly because of the %w(p p p p l p). Looking at my other Win32API calls in the game, they all have the third variable in the format of ''.

e.g.

'LPLPPP'
'L'
etc.

@orochii: Thank you for the tip! But isn't that against the terms of agreement with RPG Maker? I work on commercial games so I don't think I'm technically allowed to edit the *.dll?

And if I am allowed to change it, if someone who plays my game runs the game, would it use the dll provided in the game folder by me or the one installed on their computer? If it uses the one installed instead of the one provided by me, then it loses its function. ^^;

Edit: Okay, so the problem was that I can't have the variables start with a capital letter. The %w is fine apparently? Changed it into this:

    # Get API functions and constants
getPrivateProfileStringA = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'L')
findWindow = Win32API.new('user32','FindWindow', %w(p p), 'L')
getWindowLong = Win32API.new('user32', 'GetWindowLong', %w(L l), 'L')
gWL_STYLE = 16
wS_POPUP = 0x80000000

# Get game title
game_name = "\0" * 256
getPrivateProfileStringA.call('Game', 'Title', '', game_name, 255, ".\\Game.ini")
game_name.delete!("\0")

# Find game window
window_handle = findWindow.call('RGSS Player', game_name)

# Get window style
window_style = getWindowLong.call(window_handle, gWL_STYLE)

p window_style

# If WS_POPUP style is set, the game is fullscreen
window_style & wS_POPUP

game_name and window_handle seem to work perfectly, window_style constantly returns '0', though. :/
oh damn, it should be GWL_STYLE = -16, with a minus
I'd assume it would work with XP as well because the game window class is "RGSS Player" in XP as well
Wow, okay, something is definitely happening now! :D

I'm getting big random integers if the game is in full screen and a 0 if it's windowed. Is that correct?

So basically I can use this whenever the player enters the menu / exits the game. Check the def. If it returns '0' the player has it on windowed mode, if it returns ANY variable other than 0, the player has it in full screen? And this method is pretty reliable? ^_^
Actually, one more correction: The last line should be

window_style & _WS_POPUP != 0

I've updated the code above. Calling the method "fullscreen?" should now output true or false.
Yup, I figured as much. :D So if it's not 0 it's full screen and if it IS 0 it's windowed?
Yes. Because window_style is an "array of flags", each stored in one bit of the value. We are interested in the 32nd bit from the right, whose value is 0x80000000, so we use "&" to filter it out. This means the value will either be 0 (bit not set) or 0x8000000 (bit set) after filtering.
Omg you're a genius, thank you so much! I can finally re-activate Alt + Tab and Alt + F4! I know that irked quite a few players before (including me, lol).

Time to update all my previous games. xD
Yeah, personally I would take a non-working Alt+Tab and Alt+F4 as a dick move and be pissed about your game which obviously tries to "capture" me.
Oh, right, if you're going for commercial you can't do that "fix". I did it once just because I needed to control it. But after I changed binaries to RGSS3 ones, I didn't need that anymore.

My game has all graphics in 2x, because I started it in RM2k3, then moved to RMXP, and I wanted the option to play in half resolution, just like in RM2k3. I managed to implement it by borrowing some code from Pokémon Essentials xD... coughcough.
Only reason for me to control the Alt-Enter was because changing to fullscreen screws up the window size.

When I changed the binaries to the RGSS3 ones, I noticed that RGSS3 automatically resizes the game screen to the window size -that is, if you change the window size without making use of Graphics#resize_screen-. So I didn't needed the fix anymore, I just left the engine behave as he liked <3.
Pages: 1