Sending unicode characters to an application

(This thread was "moved" to this forum)

Hi,

I'm creating an application that detects the pressed keystrokes and sends other characters in their place. Just like a key mapper. I'm using a keyboard hook to detect the keystrokes (the one from here, if you need to know) and and then send other keys to applications system-wide.

My only problem is that I need to send non-latin characters, cyrillic characters to be more precise (in my case), and I have realized that I'm not able to simulate this the way I'm doing so far. I have researched a lot and the only thing I found was that I may have to use SendInput instead, or Windows Messages to send a WM_CHAR or something like that.

My main objective is to be able to send a unicode character to the application from where the keystroke was detected, just like as if using a Russian keyboard layout.

Thank you, FC




Answer this question

Sending unicode characters to an application

  • wencey

    Sorry, I forgot to add, can these values be of any help, or give you any idea of usage

    Public Const KEYEVENTF_UNICODE = &H4

    Public Const WM_KEYDOWN = &H100

    Public Const WM_KEYUP = &H101

    Public Const WM_CHAR = &H102

    Private Const VK_PACKET As Integer = &HE7


    And there's also a reply that was made by nico80 in my old thread before being moved:

    Hi,
    I'm trying to do a similar thing and I found this solution to work:

    INPUT inp[1];
    KEYBDINPUT ki;

    ki.wVk = 0;  // This needs to be 0
    ki.time = 0;   //  This is the timestamp for the event... just leave it 0
    ki.wScan = 225;  // The char you want to send (es in this case would be ALT+225,  or a)
    ki.dwFlags = KEYEVENTF_UNICODE;

    inp[0].type = INPUT_KEYBOARD;
    inp[0].ki = ki;

    SendInput(1, inp, sizeof(INPUT));

    This works for me for accented letters, I don't have a clue about cyrillic charachters though.

    Hope this helps

    bye
    nico



  • lax4u

    Yes I did, but I had some trouble with it, so I might as well try to resolve this problem now.
    I have this structure

    <StructLayout(LayoutKind.Explicit)> _

        Private Structure INPUT

            Dim dwType As Integer

            Dim mouseInput As MOUSEINPUT

            Dim keyboardInput As KEYBDINPUT

            Dim hardwareInput As HARDWAREINPUT

        End Structure

    And this one

    <StructLayout(LayoutKind.Explicit)> _

        Private Structure KEYBDINPUT

            <FieldOffset(0)> Public wVk As Short

            <FieldOffset(2)> Public wScan As Short

            <FieldOffset(4)> Public dwFlags As Integer

            <FieldOffset(8)> Public time As Integer

            <FieldOffset(12)> Public dwExtraInfo As IntPtr

        End Structure

     

    How would I apply the above suggestion correctly, in VB.NET

    Also, regarding this comment: "The char you want to send (es in this case would be ALT+225,  or a)", I think that using the ALT+ number to produce the cyrillic character isn't enough. I read that according to the current keyboard layout, an ALT+ combination would have different outputs.

    Thank you,
    FC



  • Joao Gomes

    When you say that you need to send the characters to an application ....Is there functions that you are trying to pass the characters to...Is it a routine that has Unicode arguments...if so check this article out that explains the use of the "Unicode" keyword in visual basic:

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

    Specifies that Visual Basic should marshal all strings to Unicode values regardless of the name of the external procedure being declared.

    When you call a procedure defined outside your project, the Visual Basic compiler does not have access to the information it needs to call the procedure correctly. This information includes where the procedure is located, how it is identified, its calling sequence and return type, and the string character set it uses. The Declare Statement creates a reference to an external procedure and supplies this necessary information.

    ....

    Declares a reference to a procedure implemented in an external file.

    [ <attributelist> ] [ accessmodifier ] [ Shadows ] [ Overloads ] _
    Declare [ charsetmodifier ] [ Sub ] name Lib "libname" _
    [ Alias "aliasname" ] [ ([ parameterlist ]) ]
    ' -or-
    [ <attributelist> ] [ accessmodifier ] [ Shadows ] [ Overloads ] _
    Declare [ charsetmodifier ] [ Function ] name Lib "libname" _
    [ Alias "aliasname" ] [ ([ parameterlist ]) ] [ As returntype ]
    charsetmodifier

    Optional. Specifies character set and file search information. Can be one of the following:



  • zeeshan hirani

    Did you try the previous suggestion
  • Sending unicode characters to an application