locked
insert state differs in processes RRS feed

  • Question

  • Hello!

     I program for audible keystrokes using RawInput.

    I test the insert state with 

    ( GetKeyState(VK_INSERT) & 1 )

    to differ the sound output 'INSERT ON' or 'INSERT OFF'

    While testing this detail it happens that simultaneous editors 

    use different insert states for typed text.

    Is this normal?

    By the way I found that if I type the INSERT key RawInput event routine is triggered with a Virtual-Key 0xFF

    Thank you for discussion

    Erhy


    • Edited by Erhy Thursday, July 16, 2020 4:36 PM grammatic
    Thursday, July 16, 2020 4:35 PM

Answers

  • Yes, it's normal for the Insert key. Different text editors can be in different Insert/Overwrite modes at the same time.
    • Marked as answer by Erhy Friday, July 17, 2020 9:09 AM
    Thursday, July 16, 2020 5:10 PM

All replies

  • Yes, it's normal for the Insert key. Different text editors can be in different Insert/Overwrite modes at the same time.
    • Marked as answer by Erhy Friday, July 17, 2020 9:09 AM
    Thursday, July 16, 2020 5:10 PM
  • Hi,

    Thanks for posting here.

    By the way I found that if I type the INSERT key RawInput event routine is triggered with a Virtual-Key 0xFF

    I get the VK key = 0x2d(VK_INSERT) could you mind share the sample you have tested?

    Here is the sample I am using:

    #include <windows.h>
    #include <iostream>
    
    using namespace std;
    BOOL registerTouchpadForInput(HWND hWnd)
    {
        RAWINPUTDEVICE rid;
        rid.dwFlags = RIDEV_NOLEGACY | RIDEV_INPUTSINK;
        rid.usUsagePage = 1;                            
        rid.usUsage = 6;// raw keyboard data only
        rid.hwndTarget = hWnd;
        return RegisterRawInputDevices(&rid, 1, sizeof(rid));
    }
    void getinputdata(LPARAM lparam)
    {
        HRAWINPUT hInput = (HRAWINPUT)lparam;
        RAWINPUT input = { 0 };
    
        UINT size = sizeof(RAWINPUT);
        GetRawInputData(hInput, RID_INPUT,&input, &size,sizeof(RAWINPUTHEADER));
        if (RIM_TYPEKEYBOARD == input.header.dwType)
        {
            std::cout << "vk:" << input.data.keyboard.VKey << std::endl;
            SHORT status = GetKeyState(VK_INSERT) & 1;
            std::cout << "status:" << status << std::endl;
        }
        return;
    }
    
    static LRESULT CALLBACK NVTouch_WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        BOOL  registrationStatus = false;
        switch (message)
        {
        case WM_CREATE:
            registrationStatus = registerTouchpadForInput(hwnd);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        case WM_INPUT:
            getinputdata(lParam);
            return DefWindowProc(hwnd, message, wParam, lParam);
        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
        }
        return 0;
    }
    
    int main()
    {
        WNDCLASSEX wndclass = {
            sizeof(WNDCLASSEX),
            CS_DBLCLKS,
            NVTouch_WindowProc,
            0,
            0,
            GetModuleHandle(0),
            LoadIcon(0,IDI_APPLICATION),
            LoadCursor(0,IDC_ARROW),
            HBRUSH(COLOR_WINDOW + 1),
            0,
            L"myclass",
            LoadIcon(0,IDI_APPLICATION)
        };
        bool isClassRegistered = false;
        isClassRegistered = RegisterClassEx(&wndclass);
        if (isClassRegistered)
        {
            std::cout << "window class registered!" << std::endl;
            //HWND window = CreateWindowEx(0, L"myclass", L"title", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, GetModuleHandle(0), 0);
            HWND window = CreateWindow(wndclass.lpszClassName, NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, GetModuleHandle(0), NULL);
            if (window)
            {
                ShowWindow(window, SW_SHOWDEFAULT);
                MSG msg;
                while (GetMessage(&msg, 0, 0, 0))
                {
                    TranslateMessage(&msg);
                    DispatchMessage(&msg);
                }
            }
        }
    }

    Best Regards,

    Drake

    This “General Windows Desktop Development Issues” Forum will be migrating to a new home on Microsoft Q&A, please refer to this sticky post for more details. 


    "Win32 API" forum will be migrating to a new home on Microsoft Q&A !
    We invite you to post new questions in the "Win32 API" forum’s new home on Microsoft Q&A !
    For more information, please refer to the sticky post.

    Friday, July 17, 2020 3:37 AM
  • my code is similar.
    the only difference is, that you use
    RIDEV_NOLEGACY for the flag to  RegisterRawInputDevices(…)

    this property cryptically for me.

    With short tests, set or not set, make no differences.

    In my debug log I read

    17:59:25|809 OnRawInput: hDevice 1 Kbd: make=002a Flags:0002 Reserved:0000 ExtraInformation:00000000, msg=0100 VK=00ff  X'0'
    17:59:25|809 MakeCode == KEYBOARD_OVERRUN_MAKE_CODE or VKey == 0xff VKey= X'FF'
    17:59:25|810 OnRawInput: hDevice 1 Kbd: make=0052 Flags:0002 Reserved:0000 ExtraInformation:00000000, msg=0100 VK=002d  X'0'
     

    Erhy

    Friday, July 17, 2020 4:01 PM