Jump to content
Sign in to follow this  
cppman

WM_CHAR

Recommended Posts

cppman

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

Share this post


Link to post
Share on other sites
Richard Robertson

The repeat count has to do with how many times it would be repeated on that message.

If you get 3 WM_CHAR's with a repeat count of 5, that would be 15 "presses" because of the repeat. This is what I understand of it.

Share this post


Link to post
Share on other sites
cppman

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;

Share this post


Link to post
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
Sign in to follow this  

×