🔒 Locked
Direct INput problems
Advertisement
Original Post
Man I have had so many problems with this...
which mode ( exclusive/nonexclusive) should I be in to capture whether or not the user has pressed the enter key? I want the program to stop and wait until the user hits that buttom, how do I do that in direct INput???
to Code, or Not To Code
In answer to your first question, either will work. In answer to your second question:
Please state the nature of the debugging emergency.
|
Please state the nature of the debugging emergency.
MAYBE I should explain what i am doing...
in my main I have this:
InitDirectDraw();
InitDirectInput(hwnd);
Example();
WaitForKB();
MessageBox(hwnd, "You Pressed a key", "Event", 1);
My example shows a bitmap. the WaitForKB uses the code you gave me ( plus the variable declarations). I am basically thinking that if the messagebox shows, then the enter button was pressed.
I tried it like this:
while(!keyState[VK_RETURN] & 0x80)
and
while(keyState[VK_RETURN] & 0x80)
the message box came up both times when i was NOT touching the keyboard.... ACK what to do???
to Code, or Not To Code
Edited by - cxi2 on November 12, 2000 3:16:37 PM
in my main I have this:
InitDirectDraw();
InitDirectInput(hwnd);
Example();
WaitForKB();
MessageBox(hwnd, "You Pressed a key", "Event", 1);
My example shows a bitmap. the WaitForKB uses the code you gave me ( plus the variable declarations). I am basically thinking that if the messagebox shows, then the enter button was pressed.
I tried it like this:
while(!keyState[VK_RETURN] & 0x80)
and
while(keyState[VK_RETURN] & 0x80)
the message box came up both times when i was NOT touching the keyboard.... ACK what to do???
to Code, or Not To Code
Edited by - cxi2 on November 12, 2000 3:16:37 PM
I had a problem similar to this just a few days ago. No matter what I did, it would still respond to the button being down, even if it wasnt. The solution I had was quite simple, really. Before you check the keyboard, or at some point in time, you have to call lpdiKeyboard->Acquire();. For me, I did this each time right before I checked the keyboard state with lpdiKeyboard->GetDeviceState(sizeof(diks),&diks); (I''m assuming this is DX7). Hopefully, this will work for you.
-Doddler
-Doddler
I think I am doing that, but it still doesnt enter the loop....
here is the code
void WaitForKB(void)
{
g_pKeyboard->Acquire();
unsigned char keystate[256];
g_pKeyboard->Acquire();
g_pKeyboard->GetDeviceState(256, &keystate); // blah
while(!keystate[DIK_RETURN] & 0x80 )
{
g_pKeyboard->Acquire();
g_pKeyboard->GetDeviceState(256, &keystate);
MessageBox(hwnd, "you have not pressed a button", "event", 1);
}
}
the message box here never comes up regardless of the keyboard
to Code, or Not To Code
here is the code
void WaitForKB(void)
{
g_pKeyboard->Acquire();
unsigned char keystate[256];
g_pKeyboard->Acquire();
g_pKeyboard->GetDeviceState(256, &keystate); // blah
while(!keystate[DIK_RETURN] & 0x80 )
{
g_pKeyboard->Acquire();
g_pKeyboard->GetDeviceState(256, &keystate);
MessageBox(hwnd, "you have not pressed a button", "event", 1);
}
}
the message box here never comes up regardless of the keyboard
to Code, or Not To Code
Stop the desperation!! 
Seriously, just calm down and I HAVE done it (albeit in windows code)..my interpretation of the DirectInput stuff is like it''s a giant lookup table and/or state machine...it just sets itself according to the input given..
ALL you have to do in your main game loop is have a check for the key..you don''t need to lock your program into an infinite loop like you''ve done..
ie..main_loop is called during the idle times of the message queue (which I''ll post if you NEED it, but it''s everywhere)
TCHAR keystate[256];
main_loop() {
g_pKeyboard->Acquire();
g_pKeyboard->getDeviceState(sizeof(keystate), &keystate);
//if we hit escape then exit
if(g_pKeyboard->isHit(DIK_ESCAPE)){
PostMessage(g_hWnd, WM_CLOSE, 0, 0);
return(-1);
}
//otherwise do your code..
//display HUGE bitmap of Algore''s ego here
}
that should be enough to get the point..if you need further help, no problem I''ll help ya out (hopefully)
Famous Last Words #141: "Phew glad that''s over. I''ll take my armour off now."
Wazoo
Seriously, just calm down and I HAVE done it (albeit in windows code)..my interpretation of the DirectInput stuff is like it''s a giant lookup table and/or state machine...it just sets itself according to the input given..
ALL you have to do in your main game loop is have a check for the key..you don''t need to lock your program into an infinite loop like you''ve done..
ie..main_loop is called during the idle times of the message queue (which I''ll post if you NEED it, but it''s everywhere)
TCHAR keystate[256];
main_loop() {
g_pKeyboard->Acquire();
g_pKeyboard->getDeviceState(sizeof(keystate), &keystate);
//if we hit escape then exit
if(g_pKeyboard->isHit(DIK_ESCAPE)){
PostMessage(g_hWnd, WM_CLOSE, 0, 0);
return(-1);
}
//otherwise do your code..
//display HUGE bitmap of Algore''s ego here
}
that should be enough to get the point..if you need further help, no problem I''ll help ya out (hopefully)
Famous Last Words #141: "Phew glad that''s over. I''ll take my armour off now."
Wazoo
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement