Files
Client/GameTools/CaldronBase/DInput8Mgr.cpp
LGram16 dd97ddec92 Restructure repository to include all source folders
Move git root from Client/ to src/ to track all source code:
- Client: Game client source (moved to Client/Client/)
- Server: Game server source
- GameTools: Development tools
- CryptoSource: Encryption utilities
- database: Database scripts
- Script: Game scripts
- rylCoder_16.02.2008_src: Legacy coder tools
- GMFont, Game: Additional resources

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 20:17:20 +09:00

445 lines
9.5 KiB
C++
Raw Permalink Blame History

// DInput9Mgr.cpp: implementation of the CDInput9Mgr class.
//
//////////////////////////////////////////////////////////////////////
#include "DInput8Mgr.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
int Caldron::Base::CDInput8Mgr::ms_iLockKey = -1;
DIMOUSESTATE Caldron::Base::CDInput8Mgr::m_MouseState;
int Caldron::Base::CDInput8Mgr::m_iMouseMove[MOUSE_AXISNUMS];
char Caldron::Base::CDInput8Mgr::m_strKeys[256];
char Caldron::Base::CDInput8Mgr::m_strBackKeys[256];
LPDIRECTINPUTDEVICE8 Caldron::Base::CDInput8Mgr::m_lpMouseDevice = NULL;
Caldron::Base::CDInput8Mgr::CDInput8Mgr()
{
m_lpKeyboardDevice = NULL;
m_lpMouseDevice = NULL;
m_lpDirectInput = NULL;
}
Caldron::Base::CDInput8Mgr::~CDInput8Mgr()
{
if(m_lpKeyboardDevice)
{
m_lpKeyboardDevice->Unacquire();
SafeRelease(m_lpKeyboardDevice);
}
if(m_lpMouseDevice)
{
m_lpMouseDevice->Unacquire();
SafeRelease(m_lpMouseDevice);
m_lpMouseDevice = NULL;
}
if(m_lpDirectInput)
{
SafeRelease(m_lpDirectInput);
}
}
HRESULT Caldron::Base::CDInput8Mgr::InitInputMgr(HINSTANCE hInstance,HWND hWnd,DWORD dwKeyboardLevel,DWORD dwMouseLevel)
{
HRESULT hr;
// direct input create
if(Failed(hr = DirectInput8Create(hInstance,DIRECTINPUT_VERSION,IID_IDirectInput8,(void **)&m_lpDirectInput,NULL)))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : DInput8 Create Failed");
return hr;
}
//device create
if(Failed(hr = m_lpDirectInput->CreateDevice(GUID_SysMouse,&m_lpMouseDevice,NULL)))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Mouse Device Create Failed");
return hr;
}
if(Failed(hr = m_lpDirectInput->CreateDevice(GUID_SysKeyboard,&m_lpKeyboardDevice,NULL)))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Keyboard Device Create Failed");
return hr;
}
//device information interface setting
if(Failed(hr = m_lpKeyboardDevice->SetDataFormat(&c_dfDIKeyboard)))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Keyboard DataFormat Set Failed");
return hr;
}
if(Failed(hr = m_lpMouseDevice->SetDataFormat(&c_dfDIMouse)))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Mouse DataFormat Set Failed");
return hr;
}
//device cooperative setting (Ű <20><EFBFBD><EEB6BB> <20><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>.)
if(Failed(hr = m_lpKeyboardDevice->SetCooperativeLevel(hWnd,dwKeyboardLevel)))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Keyboard CooperativeLevel Set Failed");
return hr;
}
if(Failed(hr = m_lpMouseDevice->SetCooperativeLevel(hWnd,dwMouseLevel)))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Mouse CooperativeLevel Set Failed");
return hr;
}
//device acquire
if(Failed(hr = m_lpKeyboardDevice->Acquire()))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : KeyBoard Acquire Failed");
return hr;
}
if(Failed(hr = m_lpMouseDevice->Acquire()))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Mouse Acquire Failed");
return hr;
}
// information update
memset(m_strKeys,0,sizeof(char) * 256);
memset(m_strBackKeys,0,sizeof(char) * 256);
if(Failed(hr = m_lpKeyboardDevice->GetDeviceState(256,&m_strKeys)))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Keyboard DeviceState Read Failed");
return hr;
}
if(Failed(hr = m_lpMouseDevice->GetDeviceState(sizeof(DIMOUSESTATE),&m_MouseState)))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Mouse DeviceState Read Failed");
return hr;
}
return S_OK;
}
HRESULT Caldron::Base::CDInput8Mgr::Acquire()
{
HRESULT hr;
if(Failed(hr = m_lpMouseDevice->Acquire()))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Mouse Acquire Failed");
return hr;
}
if(Failed(hr = m_lpKeyboardDevice->Acquire()))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Keyboard Acquire Failed");
return hr;
}
return S_OK;
}
HRESULT Caldron::Base::CDInput8Mgr::Unacquire()
{
HRESULT hr;
if(Failed(hr = m_lpMouseDevice->Unacquire()))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Mouse Unacquire Failed");
return hr;
}
if(Failed(hr = m_lpKeyboardDevice->Unacquire()))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Keyboard Unacquire Failed");
return hr;
}
return S_OK;
}
bool Caldron::Base::CDInput8Mgr ::PushButton(int index,int iKey)
{
if(ms_iLockKey != iKey)
return false;
HRESULT hr;
if(Failed(hr = m_lpMouseDevice->Acquire()))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Mouse Acquire Failed");
return false;
}
if(Failed(hr = m_lpMouseDevice->GetDeviceState(sizeof(DIMOUSESTATE),&m_MouseState)))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Mouse DeviceState Get Failed");
return false;
}
return (m_MouseState.rgbButtons[index] &0x80) ? true : false;
}
bool Caldron::Base::CDInput8Mgr::UpButton(int index,int iKey)
{
if(ms_iLockKey != iKey)
return false;
HRESULT hr;
if(Failed(hr = m_lpMouseDevice->Acquire()))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Mouse Acquire Failed");
return false;
}
if(Failed(hr = m_lpMouseDevice->GetDeviceState(sizeof(DIMOUSESTATE),&m_MouseState)))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Mouse DeviceState Get Failed");
return false;
}
return (m_MouseState.rgbButtons[index] &0x80) ? false : true;
}
bool Caldron::Base::CDInput8Mgr:: PushOnceKey(int index,int iKey)
{
if(ms_iLockKey != iKey)
return false;
bool bReturn = (m_strKeys[index] &0x80) ? true : false;
if(bReturn && (m_strBackKeys[index] != m_strKeys[index]))
return bReturn;
return false;
}
bool Caldron::Base::CDInput8Mgr::KeyStrok(char *strBuffer,int &iPos)
{
bool bPush = false;
for(int i = 0; i < 256; i++ )
{
bPush = (m_strKeys[i] &0x80) ? true : false;
if(bPush && (m_strBackKeys[i] != m_strKeys[i])) {
switch(i)
{
case 0x02:
strBuffer[iPos++] = '1';
break;
case 0x03:
strBuffer[iPos++] = '2';
break;
case 0x04:
strBuffer[iPos++] = '3';
break;
case 0x05:
strBuffer[iPos++] = '4';
break;
case 0x06:
strBuffer[iPos++] = '5';
break;
case 0x07:
strBuffer[iPos++] = '6';
break;
case 0x08:
strBuffer[iPos++] = '7';
break;
case 0x09:
strBuffer[iPos++] = '8';
break;
case 0x0A:
strBuffer[iPos++] = '9';
break;
case 0x0B:
strBuffer[iPos++] = '0';
break;
case 0x0C:
strBuffer[iPos++] = '-';
break;
case 0x0D:
strBuffer[iPos++] = '=';
break;
case 0x0E:
strBuffer[iPos--] = 0;
break;
case 0x0F:
strBuffer[iPos++] = '\t';
break;
case 0x10:
strBuffer[iPos++] = 'Q';
break;
case 0x11:
strBuffer[iPos++] = 'W';
break;
case 0x12:
strBuffer[iPos++] = 'E';
break;
case 0x13:
strBuffer[iPos++] = 'R';
break;
case 0x14:
strBuffer[iPos++] = 'T';
break;
case 0x15:
strBuffer[iPos++] = 'Y';
break;
case 0x16:
strBuffer[iPos++] = 'U';
break;
case 0x17:
strBuffer[iPos++] = 'I';
break;
case 0x18:
strBuffer[iPos++] = 'O';
break;
case 0x19:
strBuffer[iPos++] = 'P';
break;
case 0x1E:
strBuffer[iPos++] = 'A';
break;
case 0x1F:
strBuffer[iPos++] = 'S';
break;
case 0x20:
strBuffer[iPos++] = 'D';
break;
case 0x21:
strBuffer[iPos++] = 'F';
break;
case 0x22:
strBuffer[iPos++] = 'G';
break;
case 0x23:
strBuffer[iPos++] = 'H';
break;
case 0x24:
strBuffer[iPos++] = 'J';
break;
case 0x25:
strBuffer[iPos++] = 'K';
break;
case 0x26:
strBuffer[iPos++] = 'L';
break;
case 0x27:
strBuffer[iPos++] = ';';
break;
case 0x2B:
strBuffer[iPos++] = '\\';
break;
case 0x2C:
strBuffer[iPos++] = 'Z';
break;
case 0x2D:
strBuffer[iPos++] = 'X';
break;
case 0x2E:
strBuffer[iPos++] = 'C';
break;
case 0x2F:
strBuffer[iPos++] = 'V';
break;
case 0x30:
strBuffer[iPos++] = 'B';
break;
case 0x31:
strBuffer[iPos++] = 'N';
break;
case 0x32:
strBuffer[iPos++] = 'M';
break;
case 0x33:
strBuffer[iPos++] = ',';
break;
case 0x34:
strBuffer[iPos++] = '.';
break;
case 0x39:
strBuffer[iPos++] = ' ';
break;
default:
return false;
}
}
}
return bPush;
}
bool Caldron::Base::CDInput8Mgr::PushKey(int index,int iKey)
{
if(ms_iLockKey != iKey)
return false;
return (m_strKeys[index] &0x80) ? true : false;
}
bool Caldron::Base::CDInput8Mgr:: UpKey(int index,int iKey)
{
if(ms_iLockKey != iKey)
return false;
return (m_strKeys[index] &0x80) ? false : true;
}
HRESULT Caldron::Base::CDInput8Mgr::Update()
{
HRESULT hr;
// Key
// memset(m_strKeys,0,256);
if(Failed(hr = m_lpKeyboardDevice->Acquire()))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : KeyBoard Acquire Failed");
return hr;
}
memcpy(m_strBackKeys,m_strKeys,sizeof(char) * 256);
if(Failed(hr = m_lpKeyboardDevice->GetDeviceState(256,&m_strKeys)))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Keyboard DeviceState Get Failed");
return hr;
}
// Mouse
if(Failed(hr = m_lpMouseDevice->Acquire()))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Mouse Acquire Failed");
return hr;
}
if(Failed(hr = m_lpMouseDevice->GetDeviceState(sizeof(DIMOUSESTATE),&m_MouseState)))
{
CLogMgr::_LogError("CDInput8Mgr::InitInputMgr() : Mouse DeviceState Get Failed");
return hr;
}
m_iMouseMove[MOUSE_XAXIS] = m_MouseState.lX;
m_iMouseMove[MOUSE_YAXIS] = m_MouseState.lY;
return S_OK;
}
void Caldron::Base::CDInput8Mgr::GetMouseMove(int &iX,int &iY,int iKey)
{
if(ms_iLockKey != iKey)
{
iX = 0;
iY = 0;
}
iX = m_iMouseMove[MOUSE_XAXIS];
iY = m_iMouseMove[MOUSE_YAXIS];
}