CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    May 2003
    Posts
    24

    keybd_event and unicode

    guys

    i am using keybd_event() to send keystrokes to any active editor(notepad or wordpad) .

    instead of normal keystrokes, how do i send unicode values using the same function.

    i.e if 'a' is typed i want to send some unicode value of an indian language to the editor.

    can anybody help me?

    naveen

  2. #2
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,586
    In general, using keybd_event will not work for Unicode strings. The simple reason is that there are a lot more steps involved in changing a keystroke into a glyph (a displayed character). You could try sending a WM_CHAR (or WM_UNICHAR if you are using Windows XP) to the active window. This would have a higher chance of succeeding. There can be other problems though, if for example the application is using a code-page conversion, using a non-standard system locale etc.
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  3. #3
    Join Date
    Jul 2001
    Location
    Germany
    Posts
    220
    Maybe you can use ToUnicode()

    "The ToUnicode function translates the specified virtual-key code and keyboard state to the corresponding Unicode character or characters. "

  4. #4
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,586
    Interesting, I hadn't thought about that. But what you probably need is VkKeyScanExW rather than ToUnicode.
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  5. #5
    Join Date
    May 2003
    Posts
    24
    hi guys

    can u give few lines of code or any example on this

    thanks
    naveen

  6. #6
    Join Date
    Jul 2001
    Location
    Germany
    Posts
    220

    Unhappy

    Originally posted by naveenkn1977
    can u give few lines of code or any example on this
    Sorry, but I have no experience yet with these keyboard conversions. I've only used the SendInput function so far (to simulate some key input). And I will not have the time to develop a sample project now.
    Maybe you can find some sample in the MSDN (which also has a lot of stuff to read about keyboard input).
    Sorry again.
    Last edited by Matthias Kring; June 5th, 2003 at 04:11 AM.

  7. #7
    Join Date
    May 2003
    Posts
    24
    hi
    actually my code works both with sendInput() and keybd_event()

    my code ---------------

    INPUT Input[2];
    KEYBDINPUT ki;


    ki.wVk = wKeyCode;
    ki.dwFlags = KEYEVENTF_EXTENDEDKEY | 0;
    ki.time = 0;
    ki.wScan = 0;

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

    SendInput( 1, Input, sizeof(INPUT) );
    -----------------------

    in msdn i found that if i replace KEYEVENTF_EXTENDEDKEY with
    KEYEVENTF_UNICODE | KEYEVENTF_KEYUP

    then i can send unicode characters

    but when i compile it says KEYEVENTF_UNICODE undeclared variable. also i cannot find an entry for it in winuser.h

    can u help me


    thanks
    naveen

  8. #8
    Join Date
    Jul 2001
    Location
    Germany
    Posts
    220
    KEYEVENTF_UNICODE is in winuser.h, and it is only available #if(_WIN32_WINNT >= 0x0500) (that is, at least Windows 2000 is needed)

  9. #9
    Join Date
    May 2003
    Posts
    24
    hai,

    I am working on Windows XP and VC++ 6.0

    In my winuser.h file i see only following lines

    #define KEYEVENTF_EXTENDEDKEY 0x0001
    #define KEYEVENTF_KEYUP 0x0002

    There is no reference for KEYEVENTF_UNICODE

    what should i do ?

    naveen

  10. #10
    Join Date
    Jul 2001
    Location
    Germany
    Posts
    220
    Originally posted by naveenkn1977
    hai,

    I am working on Windows XP and VC++ 6.0

    In my winuser.h file i see only following lines

    #define KEYEVENTF_EXTENDEDKEY 0x0001
    #define KEYEVENTF_KEYUP 0x0002

    There is no reference for KEYEVENTF_UNICODE

    what should i do ?

    naveen
    Oops. You're right. It's not in the normal WINUSER.H.
    I've additionally installed the "Platform SDK" which comes first in path.

    Look here to get the platform SDK
    http://www.microsoft.com/msdownload/...sdk/sdkupdate/

    Matthias

  11. #11
    Join Date
    May 2003
    Posts
    24
    hi

    which SDK do i have to install ? should i install all the sdks ?

  12. #12
    Join Date
    Jul 2001
    Location
    Germany
    Posts
    220
    Originally posted by naveenkn1977
    hi

    which SDK do i have to install ? should i install all the sdks ?
    The "core" should be sufficient.
    But it's a rather huge download....

    The Platform SDK is also part of the MSDN subscription.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts



HTML5 Development Center

Click Here to Expand Forum to Full Width