directx10 user input
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: directx10 user input

  1. #1
    Join Date
    Mar 2012
    Posts
    2

    directx10 user input

    hi, this is my first post in these forums, im also quite new to programming so dont hate please just looking for some help with my direct x code that im trying to sort out. i am attempting to get user input working for the keyboard within my program the only problem im having at the moment is the error

    Unhandled exception at 0x01372146 in GameEng_Main.exe: 0xC0000005: Access violation reading location 0x00000000.

    which is then taking me to the line of

    Code:
    result = m_directInput->CreateDevice(GUID_SysKeyboard, &m_keyboard, NULL);
    the code for the actual project is:

    Code:
    #include "UserInput.h"
    
    
    
    InputClass::InputClass()
    {
    	m_directInput = 0;
    	m_keyboard = 0;
    }
    
    
    InputClass::InputClass(const InputClass& other)
    {
    }
    
    InputClass::~InputClass()
    {
    }
    
    bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd)
    {
    	HRESULT result;
    
    	//initialise the input interface
    	result = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_directInput, NULL);
    	if(!result)
    	{
    		return false;
    	}
    	
    	//create the device for the keyboard input 
     	result = m_directInput->CreateDevice(GUID_SysKeyboard, &m_keyboard, NULL);
    	if(!result)
    	{
    		return false;
    	}
    
    	//set the data format - because its the keyboard can set to predefined data format
    	result = m_keyboard->SetDataFormat(&c_dfDIKeyboard);
    	if(!result)
    	{
    		return false;
    	}
    
    	//set the cooperative level for the keyboard so it doesnt comunicate with anything else
    	result = m_keyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE);
    	if(!result)
    	{
    		return false;
    	}
    
    	// Now acquire the keyboard.
    	result = m_keyboard->Acquire();
    	if(!result)
    	{
    		return false;
    	}
    
    }
    
    void InputClass::Shutdown()
    {
    
    	//release the keyboard
    	if(m_keyboard)
    	{
    		m_keyboard->Unacquire();
    		m_keyboard->Release();
    		m_keyboard = 0;
    	}
    
    	//release the main interface
    	if(m_directInput)
    	{
    		m_directInput->Release();
    		m_directInput = 0;
    	}
    
    	return;
    
    }
    
    
    bool InputClass::Frame()
    {
    	bool result;
    
    	//read the state of the keyboard
    	result = ReadKeyboard();
    	if(!result)
    	{
    		return false;
    	}
    
    	//ProcessInput();
    
    	return true;
    }
    
    bool InputClass::ReadKeyboard()
    {
    	HRESULT result;
    
    	// Read the keyboard device.
    	result = m_keyboard->GetDeviceState(sizeof(m_keyboardState), (LPVOID)&m_keyboardState);
    	if(FAILED(result))
    	{
    		// If the keyboard lost focus or was not acquired then try to get control back.
    		if((result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED))
    		{
    			m_keyboard->Acquire();
    		}
    		else
    		{
    			return false;
    		}
    	}
    		
    	return true;
    
    }
    
    bool InputClass::IsEscapePressed()
    {
    	// Do a bitwise and on the keyboard state to check if the escape key is currently being pressed.
    	if(m_keyboardState[DIK_ESCAPE] & 0x80)
    	{
    		return true;
    	}
    
    	return false;
    }

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: directx10 user input

    Sounds like you're trying to make a keylogger, which is a subject we usually do not discuss here.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Mar 2012
    Posts
    2

    Re: directx10 user input

    noo, not at all. just trying to get user input working for a game. but it doesnt like m_keyboard.

    but i have now gone to trying to use raw input but its coming up with 0xccccccc <Bad Ptr> for the line
    Code:
    	BYTE *buffer = new BYTE[buffersize];
    tried looking around for reasons why but i cant find any

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center