Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Dtag

Scan->Charcode again

This topic is 5541 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi last time i posted someone showed me the article on this page that proposed the following function to convert scan to ascii codes: static int scan2ascii(DWORD scancode, ushort* result) { static HKL layout=GetKeyboardLayout(0); static uchar State[256]; if (GetKeyboardState(State)==FALSE) return 0; UINT vk=MapVirtualKeyEx(scancode,1,layout); return ToAsciiEx(vk,scancode,State,result,0,layout); } I created a test app where it worked fine. But in my Engine ( that uses OpenGL for drawing and DInput for input ) the code doesnt recognize that shift is pressed for example. The keyboardstate is acquired properly ( i checked it with step by step debugging ) So if i hold shift and then press h, the output is ''h'' instead of ''H''. Does anyone have an idea what could be wrong? Thanks alot

Share this post


Link to post
Share on other sites
Advertisement
If I understand you correctly you want to convert the Virtual Key Code for A (0x40) to the ascii character ''a'' (0x61). But you also say you are using Direct Input which does not use virtual keys and will return DIK_A (0x1E) for ''a''.

I have yet to find a better way to convert DIK_A to ''a'' than to create an array of characters with the index of the Direct Input code.

Share this post


Link to post
Share on other sites
I want to convert the Scancodes generated by DI to their Ascii representative considering the current Shift State etc. So if i hold shift and call that Scan2Ascii function with DIK_H as parameter for example, i want it to output ''H'' .. in my test program it does that without any problem... but in my engine it outputs ''h''

Share this post


Link to post
Share on other sites
Try creating an array of Characters with the index equal to the DIKEY.
char DI2Char[] = { ' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', ' ', '\b', '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', ... }

If IsAlpha(DI2Char[scancode]) AND Shift Key is down Then
return DI2Char[scancode] + 32
Else
return DI2Char[scancode]
End If

Hope This Helps


[edited by - Enfekted on April 20, 2003 3:44:03 PM]

Share this post


Link to post
Share on other sites
This is not the proper way to do it and it wont even work for ppl in other countries. The solution must have to do with the function i posted i guess

Share this post


Link to post
Share on other sites
I just debugged a little more... This is my function im using to get the keyboard input:


void CEngine:ollKeyboard()
{
DIDEVICEOBJECTDATA didod[16]; // Receives buffered data

if (!m_pKeyboard)
return;

DWORD dwElements = 16;
HRESULT hr = m_pKeyboard->GetDeviceData( sizeof(DIDEVICEOBJECTDATA),
didod, &dwElements, 0 );




if (hr==DIERR_INPUTLOST )
SetAcquire();

// P1
// WORD ret[2]={0};
// Scan2Ascii(DIK_H,(WORD*)&ret);

if (FAILED(hr))
{
return;
}

// P2
// WORD ret[2]={0};
// Scan2Ascii(DIK_H,(WORD*)&ret);

// Below here is some more code but that doesnt really matter to the problem


You can see the 2 comments P1 and P2 up in the code. If i test the Scan2Ascii function at P1, everything works perfectly, it can distinguish capital from normal letters and detects when shift is down etc.
At P2 it only returns normal non capital letters even while shift is down. Any ideas? Im completely clueless (

[edited by - Dtag on April 21, 2003 6:29:53 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!