Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: InputManager Issues (I think)  (Read 809 times)

Spoonsx21

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 4
    • View Profile
InputManager Issues (I think)
« on: October 03, 2009, 02:21:08 PM »

So I'm borrowing a lot of code from many places, but I can't figure out this error for the life of me.

So I'm using the InputManger.h/InputManager.cpp code from here: http://www.ogre3d.org/wiki/index.php/Using_OIS

But I changed it so that I could mess around with an already open window (I want to build a gui on top of a game to help keep track of stats in game). Point is, I'm trying to use OIS to log my keystrokes/mouse input. So I'd like to initialize OIS on a different window. As a proof of concept, I was working on getting it working with Notepad, so my program opens notepad before calling the inputmanager constructor and initialize. So I modified InputManager.h/InputManager.cpp in the following way (I changed initialise[sic]):

Code: [Select]
void InputManager::initialise(std::string winTitle) {
    if( !mInputSystem) {
        // Setup basic variables
        OIS::ParamList paramList;    //I was initially going to use OIS createinputobject using the paramList, but that didn't work so I used just the window
//handle. However, I looked at the source code, and the createinputobject code just creates a param entry anyways
        // Get window handle
        HWND Calc = FindWindow(NULL,L"Untitled - Notepad");


        // Fill parameter list
  unsigned int t = (unsigned int) Calc;
      //  paramList.insert( std::make_pair( "WINDOW", windowHndStr.str() ) ); //ignore this, it's old code, sorry

        // Create inputsystem
        mInputSystem = OIS::InputManager::createInputSystem((size_t) Calc); //I checked the handle, and it seemed to be working just fine
        // If possible create a buffered keyboard


                try{
int b2 = mInputSystem->getNumberOfDevices(OIS::OISKeyboard); //originally this was my problem, not anymore
}
catch(OIS::Exception &e)
{
std::cout << e.eText << std::endl;
}
int b2 = mInputSystem->getNumberOfDevices(OIS::OISKeyboard);
//int t2 = mInputSystem->numKeyboards() ;
if (mInputSystem->getNumberOfDevices(OIS::OISKeyboard) > 0) {
            mKeyboard = static_cast<OIS::Keyboard*>( mInputSystem->createInputObject( OIS::OISKeyboard, true ) );
            mKeyboard->setEventCallback( this );
        }

        // If possible create a buffered mouse
        // (note: if below line doesn't compile, try:  if (mInputSystem->getNumberOfDevices(OIS::OISMouse) > 0) {
        //if( mInputSystem->numMice() > 0 ) {
if (mInputSystem->getNumberOfDevices(OIS::OISMouse) > 0) {
            mMouse = static_cast<OIS::Mouse*>( mInputSystem->createInputObject( OIS::OISMouse, true ) );
            mMouse->setEventCallback( this );

            // Get window size
            // Set mouse region
this->setWindowExtents( AU3_WinGetClientSizeHeight(stringConvert(winTitle)->c_str(),TEXT(""))
,AU3_WinGetClientSizeWidth(stringConvert(winTitle)->c_str(), TEXT("")));
        }

        // If possible create all joysticks in buffered mode
        // (note: if below line doesn't compile, try:  if (mInputSystem->getNumberOfDevices(OIS::OISJoyStick) > 0) {
        //if( mInputSystem->numJoySticks() > 0 ) {
if (mInputSystem->getNumberOfDevices(OIS::OISJoyStick) > 0) {
            //mJoysticks.resize( mInputSystem->numJoySticks() );
mJoysticks.resize( mInputSystem->getNumberOfDevices(OIS::OISJoyStick) );

            itJoystick    = mJoysticks.begin();
            itJoystickEnd = mJoysticks.end();
            for(; itJoystick != itJoystickEnd; ++itJoystick ) {
                (*itJoystick) = static_cast<OIS::JoyStick*>( mInputSystem->createInputObject( OIS::OISJoyStick, true ) );
                (*itJoystick)->setEventCallback( this );
            }
        }
    }
}

The weirdest part is, when I try to run it and I put code breaks in and I use visual studio to step through the program, everything runs fine. If I try to run it without any code breaks I get this: Unhandled exception at 0x776242eb in AppSpy.exe: Microsoft C++ exception: OIS::Exception at memory location 0x0018eebc..

I really have no idea why this is happening, anything you can think of would be greatly appreciated.

Thanks guys.

Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2652
    • View Profile
    • http://www.wreckedgames.com
Re: InputManager Issues (I think)
« Reply #1 on: October 03, 2009, 02:30:16 PM »

Well, all I can think of with break points is timing... Perhaps the window you are trying to bind to is not ready. Or, maybe it is not active (or active) ie - different states. You should print/log the OIS::Exception, or otherwise get more details on what it is. And what exact line/function is failing when not running through break points. You could also run without break points via debugger and turn break on exceptions (I think that works with native code).

Logged

Spoonsx21

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 4
    • View Profile
Re: InputManager Issues (I think)
« Reply #2 on: October 03, 2009, 02:32:37 PM »

Just checked, and I'm getting a Win32Keyboard::Win32Keyboard >> acquire error. What?

EDIT: AHA! I was watching the wrong code, the other exception I received was The sent HWND was not valid.

But I checked spy++ and the Handles match up. When I converted to (unsigned int) I might have lost something? I'm not sure. Any ideas?
« Last Edit: October 03, 2009, 02:48:45 PM by Spoonsx21 »
Logged

Spoonsx21

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 4
    • View Profile
Re: InputManager Issues (I think)
« Reply #3 on: October 03, 2009, 08:05:36 PM »

Please help, I'm not sure about the bumping rules, but I've spent the last 6 hours working on this gdamn problem.

The sent HWND is not valid. I just can't figure out why not. I've checked with Spy++ that the handle coming is is absolutely right. I'm not sure if something is lost in the conversion to size_t. I checked OISInputMangager.cpp for what happens with the handle, but that wasn't too enlightening.

Could this be an issue with linking? Dynamic versus static? Would this be related? After I get that error, the keyListener doesn't do it's job. I assume this is because it doesn't have a window to act on?

Please any help is appreciated.

-Paul
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2652
    • View Profile
    • http://www.wreckedgames.com
Re: InputManager Issues (I think)
« Reply #4 on: October 03, 2009, 09:57:30 PM »

It might be easier if you would attach OIS to your own window. I'm still not really sure why you are trying to attach it to notepad.

The only reason for it to throw a not valid window is if window's says that handle is invalid. Now, you may have created OIS before showing/activating the desired window Not sure.
Logged

Spoonsx21

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 4
    • View Profile
Re: InputManager Issues (I think)
« Reply #5 on: October 04, 2009, 05:23:34 AM »

Yes it would probably be easier. However, I want to attach it to a game. I thought it would be cool to keep track of what attacks I'm using, how often, and which ones are the best. So I was doing the notepad thing as a proof of concept. I know it *should* be possible. Not that I have any interest at all making one, don't keylogger's have that abilitiy? I don't care what I'm doing in other windows though, I just want to know what I'm doing when a specific window is open.

What could be going wrong when I get the handle? I specifically include code to wait until the window is active, making absolutely sure that notepad has been called. I've confirmed the HWND with spy++, I don't know how to convert HWND to int so I can't confirm that part is correct.

Should I try it with a different program instead of notepad? Why would it be different?
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2652
    • View Profile
    • http://www.wreckedgames.com
Re: InputManager Issues (I think)
« Reply #6 on: October 07, 2009, 04:46:30 PM »

It might not be possible, it all depends on what the Window has done which will determine the success of hooking up OIS. For instance, they may have already grabbed the device for exclusive input, in which case, OIS will fail. Or, there are other things that can cause OIS initialization/connections to fail.

If you are wanting to hijack/intercept another Window's messages, you will probably want to use: SetWindowsHookEx.
Logged