Jump to content

WM_CHAR


cppman
 Share

Recommended Posts

Hello..

I am confused as to how WM_CHAR works. I understand how to use the wParam parameter of it but not the lParam.

http://msdn2.microsoft.com/en-us/library/ms646276.aspx

This gives a reference to find out the repeat count for the current message.. but doesn't really fully explain it.

Anyone know how to get it?

I'm trying to setup an input text buffer to allow easy development of custom edit-like GUI controls. Currently just getting the current character and adding it to the buffer doesn't help because the user will undoubtedly hold down the key longer than it takes to loop through the Update procedure a few times. This causes problems in which for example if they press the a key as if they were typing normally, the result would be "aaaaaa...". Does anyone know of a way to prevent this while not blocking the keys from being held down? I would like it to work exactly like a normal edit control.

Thanks.

Edited by chris95219
Link to comment
Share on other sites

Thanks,

I already found out a "more efficient" way, and it works like a charm.

if (PeekMessage(&this->m_LastMsg, NULL, 0, 0, PM_NOREMOVE)) {
            TranslateMessage(&this->m_LastMsg);
        }

        if (this->m_LastMsg.message == WM_CHAR) {
            //The user pressed a key
            char key = this->m_LastMsg.wParam;
            if (this->m_LastKey != key) {
                this->m_LastKey = key;
                switch(key)
                {
                case VK_TAB:
                    this->m_String += '\t';
                    break;
                case VK_RETURN:
                    this->m_String += '\n';
                    break;
                case VK_BACK:
                    if (this->m_String.length() > 0) {
                        this->m_String.erase(this->m_String.length()-1, this->m_String.length());
                    }
                    break;
                case VK_ESCAPE:
                    //block the escape key
                    break;
                default:
                    if (isascii(key)) {
                        this->m_String += key;
                    }
                };
            }
        } else if (this->m_LastMsg.message = WM_KEYUP) {
            this->m_LastKey = 0;
        }
        return BGE_OK;
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...