FyxInput

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by FenixFyreX, Nov 19, 2014.

  1. FenixFyreX

    FenixFyreX Fire Deity Veteran

    Messages:
    434
    Likes Received:
    307
    Location:
    A Volcano Somewhere
    First Language:
    English
    FyxInput
    FenixFyreX
    What? Another input module?
    Yep, another, but not a normal one, by far. This one has features unknown to the RPG Maker community, until now.

    Alright, what's the bells and whistles then?
    The features follow below:
    • Key input processing: press?, trigger?, release?, and repeat?
    • You can disable RPG Maker keys, like F1, F12, Alt + Enter, etc. Best. Thing. Ever. :p
    • Mouse support! Not for the actual game, in windows, but its there to be built from!
    • It's faster and more efficient. The OS does a lot of the leverage-ing.
    • Much more! Check the spoiler:
    • Ability to manually check key states if you want.
    • It's written in C. *** See below for details.
    • The keys disabled still get passed to the engine, so you can use them for whatever!
    • You can disable keys in-game too, using an add on.
    • Simulate keystrokes, and mouse buttons, but not to the system; just to the game. Safety first.
    • Key-To-Text processing. Currently, just English. I plan on adding Keyboard mapping (region specific characters, etc).
    • Game instance specific. Does not get confused when another instance of the game is open. *** See below for details.
    Queries from the Features List
    What does "Written in C" mean?
    For those who don't know, C is the language Ruby is written in (Ruby is the language RGSS is written in). Using a system Wanabe from github wrote (and I fixed up), I've recreated loading C extensions into Ruby!

    ...game instance specific?
    When most scripts are written for RPG Maker that use any API calls that would otherwise be process specific, they don't map the results to the specific process they are running in; if multiple copies of the same game are open, chances are one of the game's new script won't work, cause it got some other instance's id.
    Technical Description:
    FindWindow(), a Win32API method found in user32.dll, finds a window by it's class and caption. For any RM game, that would be "RGSS Player", and the ini file's Title variable, respectively. However, when multiple instances get opened, things go awry. To fix this, I let the OS step through the windows until it reaches the game's process id, and it selects the first window from that, aka. the game window. This pretty much fool proofs finding the handle to the game window. For programmers who use this system, just use RPG::HWND to get the game's window handle.

    Where's the goods?
    Okay, okay. Enough wasting your time with talk and text. Here's the link:
    DEMO LINK

    The demo shows off most of the things useful from this script. Many peoples' pet pieve of the F1 / F12 keys is now dead. Can't stress how nice that is to say :B

    How do I use this right?
    Well, for starters, you'll find a dll in the main folder of the game called 'mscvrt-ruby191.dll'. This is LoadSo, or the majority of it. LoadSo allows C extensions to be loaded into RGSS again, so that's necessary.
    Furthermore, there is a file called 'fyxinput.so' alongside this dll. That is needed.
    Finally, just make sure the LoadSo script and FyxInput script, and any addons from the demo are installed. That means all of this:
    • msvcrt-ruby191.dll
    • fyxinput.so
    • Two or more scripts from the demo.
    are necessary for this to work properly.

    What if I have suggestions? Any future plans for this?
    By all means, let me know! I want to further this project and make it super-efficient, which means I'm definitely not done yet, so ask and ye might receive.
    Here are some ideas for the future:
    • Region-Based KeyToText
    • Raise efficiency even more. This system was just created, now it must be optimized!
    • AddOns! I want to write mouse compatibility for RGSS' windows, etc, but that will come in time.
    • GamePad support. Not sure to what level.
    Terms Of Use
    This script is free to use non-commercially. You'll have to contact me should you wish to use it in your commercial game.

    Addons
    Fyx Per-Scene Key Disable
     
    Last edited by a moderator: Dec 3, 2014
    #1
  2. ??????

    ?????? Diabolical Codemaster Veteran

    Messages:
    6,264
    Likes Received:
    2,313
    Location:
    Your OS
    First Language:
    Binary
    Primarily Uses:
    RMMV
    Dude, I've been playing around with this since you messaged me.  This is absolutely awesome. A REAL way to remove the F Key bindings, legitimately, without having to do mad crazy sheep that barely works. Love it.

    Cant wait to see what else you add onto this. :)
     
    #2
  3. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,071
    Location:
    Toronto
    First Language:
    English
    This is great, because when someone complains that their game crashed due to my script because they pressed F12, I can just say "well then disable F12..."
     
    #3
    FenixFyreX and ?????? like this.
  4. ??????

    ?????? Diabolical Codemaster Veteran

    Messages:
    6,264
    Likes Received:
    2,313
    Location:
    Your OS
    First Language:
    Binary
    Primarily Uses:
    RMMV
    Imo we should never have had an F12 except for quick launch / playtest (maybe not even for that) - especially with how flawed it is - and seemingly has been for the past few makers.

    One would think the devs just remove it from the engine :p

    Again. Thanks to you Fenix :)
     
    #4
  5. Archeia

    Archeia Level 99 Demi-fiend Staff Member Developer

    Messages:
    14,650
    Likes Received:
    14,409
    Location:
    Game Dev Salt Mines
    First Language:
    Filipino
    Primarily Uses:
    VNM
    I was wondering, how would one change the Alt+Enter function to work differently instead?
     
    #5
  6. FenixFyreX

    FenixFyreX Fire Deity Veteran

    Messages:
    434
    Likes Received:
    307
    Location:
    A Volcano Somewhere
    First Language:
    English
    If you'd like to disable Alt + Enter, simply set the config option to true in the script. As for making Alt + Enter do something else, simply place this code somewhere in a per-frame update method after this script (or event, or wherever, I assume you have a little scripting knowledge):

    Code:
    if Input.press_any?(VKeys::LALT, VKeys::RALT) && Input.trigger?(VKeys::ENTER)  # Here is where you'd put whatever you want to happen. Note that this has to be put in  # somewhere that will get executed every frame, such as Graphics::update method.  # Perhaps, Graphics.resize_screen(screen_width, screen_height) or something.end
    I have another script coming tonight or tomorrow, FyxFullscreen. It will allow per-monitor fullscreen toggling in combination with this script.
     
    Last edited by a moderator: Nov 19, 2014
    #6
    djDarkX and Archeia like this.
  7. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,969
    Location:
    Philippines
    First Language:
    Tagalog
    Awesome. Gonna take a look at this. :)
     
    #7
  8. ??????

    ?????? Diabolical Codemaster Veteran

    Messages:
    6,264
    Likes Received:
    2,313
    Location:
    Your OS
    First Language:
    Binary
    Primarily Uses:
    RMMV
    Gotta say bro, been looking over this and all the code since I seen it and I have come to the following conclusion...

    You are a much better coder than I. :/

    Also, this script has made about 3 months worth of script writing and benchmarking and optimization on my own input script completely obsolete. 
    Yet I couldn't be happier. :D

    Finally having the F12 gone - and being able to rebind it to do some other crap is epic. Coupled with the fact I can have a legitimate reset if I wanted, using whatever key - to which I could easily add a server disconnection method into (for my online crap).... EPIC !! :D

    Wondering...

    Is it possible to be able to detect all game closes using the methods in your .so ? Would you be willing to add that? (just a small bit of code to call some method whenever the game is closed. Something like below:

    module WhenResetting  def self.resetting    # /* Left blank for me/others to insert their own ruby code # that is ran prior to the game closing. */  endendThat would be awesome :D
     
    Last edited by a moderator: Nov 20, 2014
    #8
  9. FenixFyreX

    FenixFyreX Fire Deity Veteran

    Messages:
    434
    Likes Received:
    307
    Location:
    A Volcano Somewhere
    First Language:
    English
    I'm no better than anyone else and I make my fair share of mistakes. Thanks for the compliments though :)


    I will be posting my updates / new version of LoadSo extension project soon; yes, what you ask about is possible, but I wouldn't recommend it. I'll PM you more about it.
     
    Last edited by a moderator: Nov 20, 2014
    #9
    ?????? likes this.
  10. Sophism

    Sophism Veteran Veteran

    Messages:
    36
    Likes Received:
    6
    First Language:
    English
    Hey Fenix. I've been using this script for a while now, and finally decided to replace the input script I was running before with yours.

    Now, I'm sure that I'm doing something incredibly stupid, but just in case I'm not, I've run into a weird little issue and I'm wondering if it's something about the script. (Or I'm just dense and screwed up something else somewhere.)

    So here's the scenario:

    I have chairs that I've been trying to make work like actual seats. If the player steps on a chair facing down, their character turns down and then can either step out of the seat downwards, left or right, but can't turn or move up. When the player steps out of the chair, they can freely move around again.

    Previously, I had two regions set up. One for the chair facing down, and one for the tiles neighboring the seat. And they worked like this:

    [​IMG]

    But I really disliked how the player would hitch up for a second whenever they stepped into region 60 as the game tried to remove the Direction Fix tag. This got extremely noticeable if their character was say walking in front of a bench, thus triggering the effect twice.

    So I decided to disable the up key through your script instead, and making it so it got enabled again once the player character steps out of the chair. It worked well, but then they couldn't navigate the menu properly, so I had to implement a workaround for that as well. Now, the event looks like this:

    [​IMG]

    This method created a new problem though. Whenever the player holds the Up key for more than a millisecond while stepping into region 56, it locks their character in a Turn Up, Turn Right, Turn Down loop, and the only way to break out of it is opening the menu and pressing Up twice there. I tried to simulate input to prevent this from happening, but it's either not working or I used the wrong script string:

    Input.set_keystate(VKeys::UP, Input::KEY_NONE)

    Setting the keystate to Input::KEY_UP didn't do anything either. Am I doing something wrong, or did I stumble into an actual quirky bug?
     
    Last edited by a moderator: Dec 2, 2014
    #10
  11. FenixFyreX

    FenixFyreX Fire Deity Veteran

    Messages:
    434
    Likes Received:
    307
    Location:
    A Volcano Somewhere
    First Language:
    English
    Don't use Input.disable for this usecase. Input.disable is used to tell the internals of RPG Maker that a key is not being pressed, but my system will still reveal the key being pressed to the game code, like the script database and events. Instead, replace them with Input.set_keystate(VKeys::UP, Input::KEY_NONE); this should emulate what you want.

    The disable method is to reroute key input from the internals of RPG Maker, to disable keys like F1, F12, and such. It doesn't actually disable the key to the engine itself, like so:

    Code:
    # This is how it normally worksWindows Input -------> RPG Maker ------> Input module# After FyxInput is installed and you use Input.disable it's like so:Windows Input ------> My Code ---|   RPG Maker  |-----> Input module                                 ----------------
    Does that help? I may need more context (such as if your event is parallel process, action button, etc; or perhaps a demo that i can rectify and then post the fix). Does that sould alright?
     
    #11
  12. Sophism

    Sophism Veteran Veteran

    Messages:
    36
    Likes Received:
    6
    First Language:
    English
    #12
  13. FenixFyreX

    FenixFyreX Fire Deity Veteran

    Messages:
    434
    Likes Received:
    307
    Location:
    A Volcano Somewhere
    First Language:
    English
    I think I see the problem now. The event isn't trapping the key fast enough. Here's an addon that lets you disable keys per scene.


    Fyx Key Disabler v1.0 - Pastebin


    Check out this demo to see how it works (you only need 1 region on the chair bit, and a switch, for all chairs):


    Seat Tavern - Revamp
     
    #13
    Sophism likes this.
  14. Sophism

    Sophism Veteran Veteran

    Messages:
    36
    Likes Received:
    6
    First Language:
    English
    Oh God, that worked perfectly Fenix! And the scene-specific functionality will also allow the creation of some interesting mini games too!

    You're a scholar and a gentleman. Thanks a million!  :)
     
    #14
    FenixFyreX likes this.
  15. some1one

    some1one Villager Member

    Messages:
    11
    Likes Received:
    0
    First Language:
    English
    This is great! I'm more interested in the LoadSo though. I really want to be able to use any extension I want. I was wondering if you had source code anywhere for the LoadSo project? All I could find was the original from wanabe.
     
    #15
  16. dax

    dax Veteran Veteran

    Messages:
    46
    Likes Received:
    4
    Hello!

    I tried your script too for "sitting" and it's awesome!

    I'm experiencing a weird conflict if it's not too much might I kindly ask you to take a quick glance? I tried despite my ruby knowledge being average but I just can't grasp what on earth what's the conflict.

    Basically, what happens is that when this script is also in the list, after my char "sits", the Up key stops working - just on the map, not on menus.

    http://pastebin.com/UKA0n75g

    this is the other script

    and I was able to isolate the problem:

    it occurs

    if

    #Switch to denote day or night time

      USE_SWITCH = false

      NIGHT_DAY_SWITCH = 1

      DAY_TIME_START = 6

      NIGHT_TIME_START = 18

     

    this switch is set to true

    any ideas?

    Again, I apologise, I understand that resolving compatibility issue shouldn't be your work but maybe it's something really easy actually
     
    #16
  17. WCouillard

    WCouillard Veteran Veteran

    Messages:
    42
    Likes Received:
    13
    First Language:
    English
    This script is incredible. Awesome job.
     
    #17
  18. Sixth

    Sixth Veteran Veteran

    Messages:
    2,132
    Likes Received:
    801
    First Language:
    Hungarian
    Primarily Uses:
    RMVXA
    @dax


    My wild guess would be that you use the same switch for the disable UP input event and for that in-game time script.


    Change the switch IDs in the script configurations to something different.
     
    #18
    dax likes this.
  19. dax

    dax Veteran Veteran

    Messages:
    46
    Likes Received:
    4
    Don't know if it's just me or I missed something, but with this script, Conditional branches which use Button press don't work anymore.

    Am I doing something wrong?

    Or is it because of this part:

    # There are several new ways to check input, and here they are:              #
    #                                                                              #
    #   release?(key) # Not compatible with symbols :)C, etc)                      #
    #     - This checks whether or not the key has been released. Each key release #
    #       has a cooldown of a few frames that needs to be taken into account.    #
    #                                                                              #
    #   keystate(key) # Not compatible with symbols :)C, etc)                      #
    #     - This returns the state of the key, one of the following:               #
    #       Input::KEY_NONE      # key is completely inactive.                     #
    #       Input::KEY_DOWN      # key was literally just pressed.                 #
    #       Input::KEY_TRIGGER   # key is confirmed as pressed, thus triggered     #
    #       Input::KEY_THRESHOLD # key is transitioning from trigger to repeat     #
    #       Input::KEY_UP        # key has been released                           #
    #       Input::KEY_HOLD      # key is being held down (repeat) 

    if so, if someone is kind enough to provide me the script substitute, I'd appreciate. I don't really understand.
     
    Last edited by a moderator: Aug 6, 2015
    #19
  20. Wilczek

    Wilczek Veteran Veteran

    Messages:
    31
    Likes Received:
    15
    Location:
    Poland
    First Language:
    Polish
    Does anyone have a contact with FenixFyreX? I tried reaching him by email and PM nearly 2 months ago, but none of them did the trick.
     
    #20

Share This Page