Loading ...
Sorry, an error occurred while loading the content.

Re: Strange behaviour of SendKeys

Expand Messages
  • funes666 <tomh@optiscan.com>
    ... into ... following ... Well I have answered my own question. Referring to the MSDN article on WM_KEYUP in the Windows Management section, it mentions in
    Message 1 of 2 , Feb 5, 2003
    • 0 Attachment
      > I am trying to clear an edit box by sending {HOME}+{END}{DELETE}.
      > What the app actually sees (and I have verified this by hooking
      into
      > PreTranslateMessage()) is as if I pressed and released the
      following
      > keys in sequence: HOME SHIFT END SHIFT DELETE.
      > If I just send +{END} the result is SHIFT END SHIFT.

      Well I have answered my own question. Referring to the MSDN article
      on WM_KEYUP in the Windows Management section, it mentions in
      passing that the 4 cursor keys and insert, delete, etc should have
      the extended bit set. Digging some more, you can add a flag to the
      keybd_event call to set this. If guitest.xs is patched to set this
      bit on calls to keybd_event then +{END} appears to work. This is
      only on XP, but I will check it on NT as well.

      Here is a patch:

      Compare: (<)D:\scratch\Win32-GuiTest-1.49.2\_guitest.xs (24386 bytes)
      with: (>)D:\scratch\Win32-GuiTest-1.49.2\guitest.xs (24103 bytes)

      63d63
      < #define EXTENDED_FLAG 0x10000
      79,81c78,80
      < "DEL", VK_DELETE | EXTENDED_FLAG,
      < "DOW", VK_DOWN | EXTENDED_FLAG,
      < "END", VK_END | EXTENDED_FLAG,
      ---
      > "DEL", VK_DELETE,
      > "DOW", VK_DOWN,
      > "END", VK_END,
      85,95c84,94
      < "HOM", VK_HOME | EXTENDED_FLAG,
      < "INS", VK_INSERT | EXTENDED_FLAG,
      < "LEF", VK_LEFT | EXTENDED_FLAG,
      < "NUM", VK_NUMLOCK,
      < "PGD", VK_NEXT | EXTENDED_FLAG,
      < "PGU", VK_PRIOR | EXTENDED_FLAG,
      < "PRT", VK_SNAPSHOT,
      < "RIG", VK_RIGHT | EXTENDED_FLAG,
      < "SCR", VK_SCROLL,
      < "TAB", VK_TAB,
      < "UP", VK_UP | EXTENDED_FLAG,
      ---
      > "HOM", VK_HOME,
      > "INS", VK_INSERT,
      > "LEF", VK_LEFT,
      > "NUM", VK_NUMLOCK,
      > "PGD", VK_NEXT,
      > "PGU", VK_PRIOR,
      > "PRT", VK_SNAPSHOT,
      > "RIG", VK_RIGHT,
      > "SCR", VK_SCROLL,
      > "TAB", VK_TAB,
      > "UP", VK_UP,
      246,247c245,246
      < unsigned extended = vk & EXTENDED_FLAG ?
      KEYEVENTF_EXTENDEDKEY : 0;
      < keybd_event(vk & 0xff, scan, KEYEVENTF_KEYUP | extended, 0);
      ---
      > BYTE scan = MapVirtualKey(vk, 0);
      > keybd_event(vk, scan, KEYEVENTF_KEYUP, 0);
      252,253c251,252
      < unsigned extended = vk & EXTENDED_FLAG ?
      KEYEVENTF_EXTENDEDKEY : 0;
      < keybd_event(vk, 0, extended, 0);
      ---
      > BYTE scan=MapVirtualKey(vk, 0);
      > keybd_event(vk, scan, 0, 0);

      TomH <tomh(AT)optiscan(DOT)com>
    Your message has been successfully submitted and would be delivered to recipients shortly.