+ Reply to Thread
Results 1 to 5 of 5

Can't send specific LEFT or RIGHT Ctrl- or Alt-key with keybd_event ?

  1. #1
    Registered User
    Join Date
    03-22-2009
    Location
    Antwerp
    MS-Off Ver
    Excel 2002 SP2
    Posts
    45

    Can't send specific LEFT or RIGHT Ctrl- or Alt-key with keybd_event ?

    I can't seem to send a specific LEFT or RIGHT Ctrl or Alt, or is it that I can't read it out... ?
    I made a little test sub: (delete the gray part in Declare if you don't have a 64bit Excel)

    Please Login or Register  to view this content.
    output:
    Please Login or Register  to view this content.
    The R should be L !!!
    Also I can't seem to send only the Alt-R without also pressing Ctrl-L !?

    HELP ME, thanks

  2. #2
    Registered User
    Join Date
    03-22-2009
    Location
    Antwerp
    MS-Off Ver
    Excel 2002 SP2
    Posts
    45

    Re: Can't send specific LEFT or RIGHT Ctrl- or Alt-key with keybd_event ?

    Reply to my selve I think I solved it.

    I made the test a bit better and although previous code worked the vDown and vUp where wrongly named. Sorry for that.

    I found out that there is something weird going on but I think I may have found a solution.
    It seems there is a little flow in the keybd_event and Ms doesn't tell us that here!


    KEYEVENTF_EXTENDEDKEY (bit 1) should not be used for modifying keys (Shift, Ctrl, Alt,...)
    Unless you want to send Ctrl-R or Alt-R, and even more troubling you need to send Alt-L instead of Alt-R

    So apart from the Alt-L instead of Alt-R which could have something to do with the AltGr, only the Right Ctrl and Right Alt keys are considered to be KEYEVENTF_EXTENDEDKEY !

    Can anyone please confirm my conclusion? Just try this code and check if the output is the same as mine, on Win7, 64bit Excel
    Thank you.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,417

    Re: Can't send specific LEFT or RIGHT Ctrl- or Alt-key with keybd_event ?

    Hi,

    Ran in win7, Excel-64...

    Please Login or Register  to view this content.
    abousetta

    N.B. Don't bother declaring integers in Excel 2010 because it gets converted to long... add declarations for i and vWin
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  4. #4
    Registered User
    Join Date
    03-22-2009
    Location
    Antwerp
    MS-Off Ver
    Excel 2002 SP2
    Posts
    45

    Re: Can't send specific LEFT or RIGHT Ctrl- or Alt-key with keybd_event ?

    Hey, thanks!

    So it seems you never touch Ctrl with just sending AltR! Do you maybe have an actual right Alt or maybe it's because you don't have the AltGr?
    But it does show you also need to use the extended key (bit1) only for sending Ctrl-R en Alt-R

    Now I need to find a way to get the scancode of every key.
    What API tells you what key is an extended key?


    PS: Strange that your missing the outlining spaces between Shift, Ctrl and Alt running my code!?
    you: Alt 56 Alt-L
    mine: Alt 56 Alt-L

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,417

    Re: Can't send specific LEFT or RIGHT Ctrl- or Alt-key with keybd_event ?

    I'll be honest, I removed the extra spaces to make it more readable. Do you want me to re-run it again?

    I'm not an expert on API's, even though I dabble in them from time to time, so I'm sorry I won't be able to provide you with much insight into the issues themselves.

    abousetta

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1