Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems in RMX-OS, Input.update #72

Closed
khkramer opened this issue Oct 13, 2014 · 14 comments
Closed

Problems in RMX-OS, Input.update #72

khkramer opened this issue Oct 13, 2014 · 14 comments

Comments

@khkramer
Copy link

def self.update
      # get current language layout
      @language_layout = GetKeyboardLayout.call(0)
      # get new keyboard state
      GetKeyboardState.call(@state)
      # this special code is used because Ruby 1.9.x does not return a char
      # when using String#[] but another String
      key = 0
      @state.each_byte {|byte|
        # if pressed state
        if (byte & DOWN_STATE_MASK) == DOWN_STATE_MASK
          puts 'yoloth'
          # not released anymore
          @released[key] = false
          # if not pressed yet
          unless @pressed[key]
            # pressed and triggered
            @pressed[key] = true
            @triggered[key] = true
            @repeatedKey = key
            @repeatedCount = 0
            puts "pressed key:" + key.to_s
          else
            # not triggered anymore
            @triggered[key] = false
          end
          # update of repeat counter
          if key == @repeatedKey
            @repeatedCount < 17 ? @repeatedCount += 1 : @repeatedCount = 15
          end
          # not released yet
        elsif !@released[key]
          # if still pressed
          if @pressed[key]
            # not triggered, pressed or repeated, but released
            @triggered[key] = false
            @pressed[key] = false
            @released[key] = true
            if key == @repeatedKey
              @repeatedKey = -1
              @repeatedCount = 0
            end
          end
        else
          # not released anymore
          @released[key] = false
        end
        key += 1
        #puts 'key:' + key.to_s
      }
    end

This is the update method in question, it's working fine in vanilla rpgxp, the rpgvx ace player and arc.

The problem is that this piece of code always returns false:

if (byte & DOWN_STATE_MASK) == DOWN_STATE_MASK

While it should return true when a key is being pressed.

I have tried changing several things but none have worked so far.

@Ancurio
Copy link
Owner

Ancurio commented Oct 13, 2014

And this is on Windows, yes?

@khkramer
Copy link
Author

This is on Windows yes.

I've managed a temporary fix after some tinkering, by including another call to Win32API:

GetKeyState=Win32API.new("user32", "GetKeyState", "I", "I")
GetKeyState.call(0)

This makes input work just fine it has just one very big side-effect.

It continues grabbing and updating keystrokes even when the application isn't active/minimized.

Do you have any plans of adding full-keyboard input to mkxp, perhaps?

@Ancurio
Copy link
Owner

Ancurio commented Oct 13, 2014

Do you have any plans of adding full-keyboard input to mkxp, perhaps?

Yes, see #70. I'm still thinking about the best way to write something generic that can cover as many use cases as possible. I will probably open a separate issue for it soon.

@Ancurio
Copy link
Owner

Ancurio commented Oct 15, 2014

I created an issue for general keyboard input: #73. As for your specific problem khkramer, it could be related to how SDL sets up its window and processes messages on Windows. Why do you need it to work so badly btw., I thought you were trying to port the code over to mkxp anyway?

@khkramer
Copy link
Author

Well I had to have the chat functional to test a lot of things, and I didn't know if you were going to add full keyboard input or something that allows us to use those full keyboard input scripts, so my plan was originally to first fix it on windows and then look up if there are similar api calls on Linux.

I'm pretty sure it's how SDL set up its windows then, since I'm checking the thread id of the caller (so the game) and then checking the thread id of the foreground window, and then comparing them to see if the game has focus and is in the foreground. However even when it is the foreground window it returns another thread id for the window than the 'normal' thread id if that makes sense

@Ancurio
Copy link
Owner

Ancurio commented Oct 22, 2014

Added full keyboard support to mkxp, you can check my win32 wrapper for how to use it.

@khkramer
Copy link
Author

Cool.

I'll try it out later today, and let you know how it worked.

@Ancurio
Copy link
Owner

Ancurio commented Nov 20, 2014

Closing this for now, reopen if you need to.

@Ancurio Ancurio closed this as completed Nov 20, 2014
@khkramer
Copy link
Author

khkramer commented Jan 9, 2015

Very very late response from me :)

It works like a charm, however it breaks mouseclicks for me.
I've found the cause as well, in Input.h, MouseLeft has scancode 0x38, while in the RMX-OS input script and your win32-wrapper the 'Up' key has scancode 0x38. So whenever I press the up key it thinks the left mouse is being clicked as well, while clicking the actual left mouse does nothing.

@Ancurio
Copy link
Owner

Ancurio commented Jan 9, 2015

Oh, I see, it's because you're overriding Input functions so my wrapper ends up calling your modified code. The proper fix on the mkxp side is to just completely remove the mouse extensions from Input and stash them into MKXP (which I should have done from the start), but until that change has landed, the quick fix is to save an alias to the original update function and call that in the win32 wrapper instead.

@khkramer
Copy link
Author

khkramer commented Jan 9, 2015

Input.update isn't being called in the win32-wrapper??

@Ancurio
Copy link
Owner

Ancurio commented Jan 9, 2015

Oh sorry, brainfart. I meant press? of course.

@khkramer
Copy link
Author

I saved an alias like this

module Input
  class << self
    alias_method(:win32wrap_press?, :press?)
    def press?(num)
      win32wrap_press?(num)
    end
  end
end

And called that instead and it's not detecting arrow keys as mouse buttons anymore, however actual mouse clicks still aren't detected.

Edit: Tried another input script with which it does work. So this problem is pretty much fixed on my end.

@Ancurio
Copy link
Owner

Ancurio commented Jan 10, 2015

I'd still be interested into why Mouse input didn't work the first time, but oh well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants