Using a low-level keyboard hook to change keyboard characters

前端 未结 1 1444
情歌与酒
情歌与酒 2021-01-21 23:31

I\'m creating a custom keyboard layout. As the beginning step, I want to have the user press a key, have my keyboard hook intercept it, and output a different key of my choosing

1条回答
  •  臣服心动
    2021-01-22 00:20

    The second parameter for Marshal.PtrToStructure must be a class not a struct and KBDLLHOOKSTRUCT is probably a struct.

    Instead you should use it like this:

    KBDLLHOOKSTRUCT replacementKey = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
    replacementKey.vkCode = 90; // char 'Z'
    Marshal.StructureToPtr(replacementKey, lParam, false);
    

    0 讨论(0)
提交回复
热议问题