Im trying to make a keyup function, and I just can''t figure out how to do it in a smart way

Anyone know how? Please help me!
#define KEY_DOWN(key) (key_buffer[key] & 0x80)
void cInput::DInput_Update()
{
HRESULT hr;
//First, check to see if the keyboard is still working/functioning
hr = (lpdi_keyboard->GetDeviceState(sizeof(UCHAR[256]),(LPVOID)&key_buffer));
if(FAILED(hr))
{
if(hr==DIERR_INPUTLOST)
{
//Try to re-acquire the keyboard
hr = (lpdi_keyboard->Acquire());
if(FAILED(hr))
{
MessageBox(g_HWND, "Keyboard has been lost", "dInput error", MB_OK);
DInput_Shutdown();
}
}
}
}