Home All Groups Group Topic Archive Search About

Generic SendInput samples?

Author
14 Nov 2007 9:23 PM
Karl E. Peterson
Rick Rothstein (MVP - VB) wrote:
>>>> 432 Days, 20 Hours, 13 Minutes, and 15 Seconds
>>>
>>> This is new... what are you counting down (or up)?
>>
>> ?now + 432 + 20/24  <bg>
>> --
>> 432 Days, 19 Hours, 55 Minutes, and 52 Seconds
>
> Ah yes... **that** date.  Can't wait (and its still too far off)!

Understatement of the millenium, there!  :-)

Hey, I'm cobbling together a little utility here, and thought I'd use it as an
excuse to come up to speed with SendInput.  What I can't really seem to find are any
intelligible samples out there for this function.  Am I missing something really
obvious, or did this one just pass the ClassicVB crowd by?

Thanks...   Karl
--
432 Days, 19 Hours, 36 Minutes, and 23 Seconds

Author
15 Nov 2007 2:53 AM
Karl E. Peterson
Karl E. Peterson wrote:
> Hey, I'm cobbling together a little utility here, and thought I'd use it as an
> excuse to come up to speed with SendInput.  What I can't really seem to find are
> any intelligible samples out there for this function.  Am I missing something
> really obvious, or did this one just pass the ClassicVB crowd by?

Nice enhancement, Bob!  Wanted to get that here, up front.

I've been twiddling away, as well.  This is what I've got, indented to highlight
wordwrap:

' ================================= BOF: MSendInput.bas
=================================
   Option Explicit

   Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long,
pInputs As Any, ByVal cbSize As Long) As Long
   Public Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal cChar As
Byte) As Integer

   Private Type KeyboardInput       '   typedef struct tagINPUT {
      dwType As Long                '     DWORD type;
      wVK As Integer                '     union {MOUSEINPUT mi;
      wScan As Integer              '               KEYBDINPUT ki;
      dwFlags As Long               '               HARDWAREINPUT hi;
      dwTime As Long                '              };
      dwExtraInfo As Long           '     }INPUT, *PINPUT;
      dwPadding As Currency         '   8 extra bytes, because mouses take more.
   End Type

   Private Const INPUT_MOUSE As Long = 0
   Private Const INPUT_KEYBOARD As Long = 1

   Private Const KEYEVENTF_KEYUP As Long = 2

   Private m_Data As String
   Private m_DatPtr As Long
   Private m_Events() As KeyboardInput
   Private m_EvtPtr As Long

   Private m_NamedKeys As Collection
   Private m_ShiftFlags As Long

   Private Const defBufferSize As Long = 1024

   Public Sub MySendKeys(Data As String)
      Dim i As Long

      ' Make sure our collection of named keys has been built.
      If m_NamedKeys Is Nothing Then
         Call BuildNamedKeys
      End If

      ' Clear buffer, reset pointers, and cache send data.
      ReDim m_Events(0 To defBufferSize - 1) As KeyboardInput
      m_EvtPtr = 0
      m_DatPtr = 0
      m_Data = Data

      ' Loop through entire passed string.
      Do While m_DatPtr < Len(Data)
         ' Process next token in data string.
         Call DoNext

         ' Make sure there's still plenty of room in the buffer.
         If m_EvtPtr >= (UBound(m_Events) - 24) Then
            ReDim Preserve m_Events(0 To (UBound(m_Events) + defBufferSize) - 1)
         End If
      Loop

      ' Send the processed string to the foreground window!
      If m_EvtPtr > 0 Then
         ' All events are keyboard based.
         For i = 0 To m_EvtPtr - 1
            m_Events(i).dwType = INPUT_KEYBOARD
         Next i
         ' m_EvtPtr is 0-based, but nInputs is 1-based.
         Debug.Print SendInput(m_EvtPtr, m_Events(0), Len(m_Events(0))),
         Debug.Print Err.LastDllError
      End If
   End Sub

   Private Sub DoNext()
      Dim this As String

      ' Advance data pointer, and extract next char.
      m_DatPtr = m_DatPtr + 1
      this = Mid$(m_Data, m_DatPtr, 1)

      ' Branch to appropriate helper routine.
      If InStr("+^%", this) Then
         Call ProcessShift(this)
      ElseIf this = "(" Then
         Call ProcessGroup
      ElseIf this = "{" Then
         Call ProcessNamedKey
      Else
         Call ProcessChar(this)
      End If
   End Sub

   Private Sub ProcessChar(this As String)
      Dim vk As Integer
      Dim capped As Boolean
      ' Add input events for single character, taking capitalization
      ' into account.  HiByte will contain the shift state, and LoByte
      ' will contain the key code.
      vk = VkKeyScan(Asc(this))
      capped = CBool(ByteHi(vk) And 1)
      vk = ByteLo(vk)
      Call StuffBuffer(vk, capped)
   End Sub

   Private Sub ProcessGroup()
      Dim EndPtr As Long
      Dim this As String
      Dim i As Long
      ' Groups of characters are offered together, surrounded by parenthesis,
      ' in order to all be modified by shift key(s).  We need to dig out the
      ' remainder of the group, and process each in turn.
      EndPtr = InStr(m_DatPtr, m_Data, ")")
      ' No need to do anything if endgroup immediateyl follows beginning.
      If EndPtr > (m_DatPtr + 1) Then
         For i = 1 To (EndPtr - m_DatPtr - 1)
            this = Mid$(m_Data, m_DatPtr + i, 1)
            Call ProcessChar(this)
         Next i
         ' Advance data pointer to closing parenthesis.
         m_DatPtr = EndPtr
      End If
   End Sub

   Private Sub ProcessNamedKey()
      Dim EndPtr As Long
      Dim this As String
      Dim pieces() As String
      Dim repeat As Long
      Dim vk As Integer
      Dim capped As Boolean
      Dim i As Long

      ' Groups of characters are offered together, surrounded by braces,
      ' representing a named keystroke.  We need to dig out the actual
      ' name, and optionally the number of times this keystroke is repeated.
      EndPtr = InStr(m_DatPtr, m_Data, "}")
      ' No need to do anything if endgroup immediately follows beginning.
      If EndPtr > (m_DatPtr + 1) Then
         ' Extract group of characters.
         this = Mid$(m_Data, m_DatPtr + 1, EndPtr - m_DatPtr - 1)

         ' Break into pieces, if possible.
         pieces = Split(this, " ")

         ' Second element, if avail, is number of times to repeat stroke.
         If UBound(pieces) > 0 Then repeat = Val(pieces(1))
         If repeat < 1 Then repeat = 1

         ' Attempt to retrieve named keycode, or else retrieve standard code.
         vk = GetNamedKey(pieces(0))
         If vk = 0 Then
            vk = VkKeyScan(Asc(this))
            capped = CBool(ByteHi(vk) And 1)
            vk = ByteLo(vk)
         End If

         ' Stuff buffer as many times as required.
         For i = 1 To repeat
            Call StuffBuffer(vk, capped)
         Next i

         ' Advance data pointer to closing parenthesis.
         m_DatPtr = EndPtr
      End If
   End Sub

   Private Sub ProcessShift(shiftkey As String)
      ' Press appropriate shiftkey.
      With m_Events(m_EvtPtr)
         Select Case shiftkey
            Case "+"
               .wVK = vbKeyShift
               m_ShiftFlags = m_ShiftFlags Or vbShiftMask
            Case "^"
               .wVK = vbKeyControl
               m_ShiftFlags = m_ShiftFlags Or vbCtrlMask
            Case "%"
               .wVK = vbKeyMenu
               m_ShiftFlags = m_ShiftFlags Or vbAltMask
         End Select
      End With
      m_EvtPtr = m_EvtPtr + 1

      ' Process next set of data
      Call DoNext

      ' Unpress same shiftkey.
      With m_Events(m_EvtPtr)
         Select Case shiftkey
            Case "+"
               .wVK = vbKeyShift
               m_ShiftFlags = m_ShiftFlags And Not vbShiftMask
            Case "^"
               .wVK = vbKeyControl
               m_ShiftFlags = m_ShiftFlags And Not vbCtrlMask
            Case "%"
               .wVK = vbKeyMenu
               m_ShiftFlags = m_ShiftFlags And Not vbAltMask
         End Select
         .dwFlags = KEYEVENTF_KEYUP
      End With
      m_EvtPtr = m_EvtPtr + 1
   End Sub

   Private Sub StuffBuffer(ByVal vk As Integer, Shifted As Boolean)
      ' Only mess with Shift key if not already pressed.
      If CBool(m_ShiftFlags And vbShiftMask) = False Then
         If Shifted Then
            With m_Events(m_EvtPtr)
               .wVK = vbKeyShift
            End With
            m_EvtPtr = m_EvtPtr + 1
         End If
      End If

      ' Press and release this key.
      With m_Events(m_EvtPtr)
         .wVK = vk
      End With
      m_EvtPtr = m_EvtPtr + 1
      With m_Events(m_EvtPtr)
         .wVK = vk
         .dwFlags = KEYEVENTF_KEYUP
      End With
      m_EvtPtr = m_EvtPtr + 1

      ' Only mess with Shift key if not already pressed.
      If CBool(m_ShiftFlags And vbShiftMask) = False Then
         If Shifted Then
            With m_Events(m_EvtPtr)
               .wVK = vbKeyShift
               .dwFlags = KEYEVENTF_KEYUP
            End With
            m_EvtPtr = m_EvtPtr + 1
         End If
      End If
   End Sub

   Private Function ByteHi(ByVal WordIn As Integer) As Byte
      ' Lop off low byte with divide. If less than
      ' zero, then account for sign bit (adding &h10000
      ' implicitly converts to Long before divide).
      If WordIn < 0 Then
         ByteHi = (WordIn + &H10000) \ &H100
      Else
         ByteHi = WordIn \ &H100
      End If
   End Function

   Private Function ByteLo(ByVal WordIn As Integer) As Byte
      ' Mask off high byte and return low.
      ByteLo = WordIn And &HFF
   End Function

   Private Function GetNamedKey(this As String) As Integer
      Dim nRet As Integer
      ' Try retrieving from collection
      On Error Resume Next
         GetNamedKey = m_NamedKeys(UCase$(this))
      On Error Resume Next
   End Function

   Private Sub BuildNamedKeys()
      ' Build collection containing all known named keys.
      Set m_NamedKeys = New Collection
      With m_NamedKeys
         .Add vbKeyBack, "BACKSPACE"
         .Add vbKeyBack, "BS"
         .Add vbKeyBack, "BKSP"
         .Add vbKeyPause, "BREAK"
         .Add vbKeyCapital, "CAPSLOCK"
         .Add vbKeyDelete, "DELETE"
         .Add vbKeyDelete, "DEL"
         .Add vbKeyDown, "DOWN"
         .Add vbKeyEnd, "END"
         .Add vbKeyReturn, "ENTER"
         .Add vbKeyReturn, "~"
         .Add vbKeyEscape, "ESC"
         .Add vbKeyHelp, "HELP"
         .Add vbKeyHome, "HOME"
         .Add vbKeyInsert, "INS"
         .Add vbKeyInsert, "INSERT"
         .Add vbKeyLeft, "LEFT"
         .Add vbKeyNumlock, "NUMLOCK"
         .Add vbKeyPageDown, "PGDN"
         .Add vbKeyPageUp, "PGUP"
         .Add vbKeyPrint, "PRTSC"
         .Add vbKeyRight, "RIGHT"
         .Add vbKeyScrollLock, "SCROLLLOCK"
         .Add vbKeyTab, "TAB"
         .Add vbKeyUp, "UP"
         .Add vbKeyF1, "F1"
         .Add vbKeyF2, "F2"
         .Add vbKeyF3, "F3"
         .Add vbKeyF4, "F4"
         .Add vbKeyF5, "F5"
         .Add vbKeyF6, "F6"
         .Add vbKeyF7, "F7"
         .Add vbKeyF8, "F8"
         .Add vbKeyF9, "F9"
         .Add vbKeyF10, "F10"
         .Add vbKeyF11, "F11"
         .Add vbKeyF12, "F12"
         .Add vbKeyF13, "F13"
         .Add vbKeyF14, "F14"
         .Add vbKeyF15, "F15"
         .Add vbKeyF16, "F16"
      End With
   End Sub
' ================================= EOF: MSendInput.bas
=================================

Seems to work *exactly* like SendKeys, but it has a fatal flaw.  I can't seem to
highlight for some reason?  The shiftkeys are simply not working with the named
keys.  For example, try this:

   Private Sub Command1_Click()
      Text1.SetFocus
      DoEvents
      Call MySendKeys("{home}+{end}")
   End Sub

Oughta highlight the entire textbox, right?  Not doing it.  Conversely, this works:

      Call MySendKeys("{end}+{j 4}")

Stuffs "JJJJ" at the end of the textbox.  This, and walking the code, both show the
Shiftkey is absolutely down through that entire {} group.  Anyone see the flaw?

Thanks...   Karl
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
15 Nov 2007 3:05 PM
Bob Butler
Show quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:uVHqCLzJIHA.4272@TK2MSFTNGP05.phx.gbl...
> Karl E. Peterson wrote:
>> Hey, I'm cobbling together a little utility here, and thought I'd use it
>> as an
>> excuse to come up to speed with SendInput.  What I can't really seem to
>> find are
>> any intelligible samples out there for this function.  Am I missing
>> something
>> really obvious, or did this one just pass the ClassicVB crowd by?
>
> Nice enhancement, Bob!  Wanted to get that here, up front.
>
> I've been twiddling away, as well.  This is what I've got, indented to
> highlight wordwrap:
<cut>
> Seems to work *exactly* like SendKeys, but it has a fatal flaw.  I can't
> seem to highlight for some reason?  The shiftkeys are simply not working
> with the named keys.  For example, try this:
>
>   Private Sub Command1_Click()
>      Text1.SetFocus
>      DoEvents
>      Call MySendKeys("{home}+{end}")
>   End Sub

I tried it and can't get it to fail (using Vista).  It highlight perfectly.
Author
15 Nov 2007 4:00 PM
Bob Butler
Show quote
"Bob Butler" <noway@nospam.ever> wrote in message
news:uCcGyk5JIHA.1188@TK2MSFTNGP04.phx.gbl...
> "Karl E. Peterson" <k***@mvps.org> wrote in message
> news:uVHqCLzJIHA.4272@TK2MSFTNGP05.phx.gbl...
>> Karl E. Peterson wrote:
>>> Hey, I'm cobbling together a little utility here, and thought I'd use it
>>> as an
>>> excuse to come up to speed with SendInput.  What I can't really seem to
>>> find are
>>> any intelligible samples out there for this function.  Am I missing
>>> something
>>> really obvious, or did this one just pass the ClassicVB crowd by?
>>
>> Nice enhancement, Bob!  Wanted to get that here, up front.
>>
>> I've been twiddling away, as well.  This is what I've got, indented to
>> highlight wordwrap:
> <cut>
>> Seems to work *exactly* like SendKeys, but it has a fatal flaw.  I can't
>> seem to highlight for some reason?  The shiftkeys are simply not working
>> with the named keys.  For example, try this:
>>
>>   Private Sub Command1_Click()
>>      Text1.SetFocus
>>      DoEvents
>>      Call MySendKeys("{home}+{end}")
>>   End Sub
>
> I tried it and can't get it to fail (using Vista).  It highlight
> perfectly.


I added some debugging lines to dump the events and then report the
text1_keydown and text1_keyup events.  Under Vista I get this:

MySendKeys "{home}+{end}"
0:1            36            0
1:1            36            2
2:1            16            0
3:1            35            0
4:1            35            2
5:1            16            2
6             6             0
keydown 36     0
keyup 36       0
keydown 16     1
keydown 35     1
keyup 35       1
keyup 16       0

That shows the 6 keyboard events, the call to SendInput, then the textbox
events and it's all exactly what it should be and the text is highlighted.

When I run it under Win2K I get this:

MySendKeys "{home}+{end}"
0:1            36            0
1:1            36            2
2:1            16            0
3:1            35            0
4:1            35            2
5:1            16            2
6             6             0
keydown 36     0
keyup 36       0
keydown 16     1
keyup 16       0
keydown 35     0
keyup 35       0
keydown 16     1
keyup 16       0

The buffer and SendInput look fine but the textbox receives 2 extra
keystrokes making the shift key not stick for the END key.

Interestingly, if I do just SendKeys it sends the correct keystrokes
followed by
keydown 144    0
keyup 144      0
keydown 144    0
keyup 144      0
Author
15 Nov 2007 5:47 PM
Karl E. Peterson
Bob Butler wrote:
>> I tried it and can't get it to fail (using Vista).  It highlight
>> perfectly.

Argh!

Show quote
> I added some debugging lines to dump the events and then report the
> text1_keydown and text1_keyup events.  Under Vista I get this:
>
> MySendKeys "{home}+{end}"
> 0:1            36            0
> 1:1            36            2
> 2:1            16            0
> 3:1            35            0
> 4:1            35            2
> 5:1            16            2
> 6             6             0
> keydown 36     0
> keyup 36       0
> keydown 16     1
> keydown 35     1
> keyup 35       1
> keyup 16       0
>
> That shows the 6 keyboard events, the call to SendInput, then the textbox
> events and it's all exactly what it should be and the text is highlighted.
>
> When I run it under Win2K I get this:
>
> MySendKeys "{home}+{end}"
> 0:1            36            0
> 1:1            36            2
> 2:1            16            0
> 3:1            35            0
> 4:1            35            2
> 5:1            16            2
> 6             6             0
> keydown 36     0
> keyup 36       0
> keydown 16     1
> keyup 16       0
> keydown 35     0
> keyup 35       0
> keydown 16     1
> keyup 16       0
>
> The buffer and SendInput look fine but the textbox receives 2 extra
> keystrokes making the shift key not stick for the END key.
>
> Interestingly, if I do just SendKeys it sends the correct keystrokes
> followed by
> keydown 144    0
> keyup 144      0
> keydown 144    0
> keyup 144      0

Too damn weird!!!  I'm getting something similar (XP/SP2), now that I look at that:

    36            0
    36            2
    16            0
    35            0
    35            2
    16            2
   Text1_KeyDown(36, 0)   {Home}
   Text1_KeyUp(36, 0)
   Text1_KeyDown(16, 1)   {Shift}
   Text1_KeyUp(16, 0)
   Text1_KeyDown(35, 0)   {End}
   Text1_KeyUp(35, 0)
   Text1_KeyDown(16, 1)   {Shift}
   Text1_KeyUp(16, 0)

That makes no dang sense.  And this is what I see (same thing) in Spy++, with a
compiled EXE:

<00017> 001B084E P WM_KEYDOWN nVirtKey:VK_HOME cRepeat:1 ScanCode:00 fExtended:0
fAltDown:0 fRepeat:0 fUp:0
<00018> 001B084E P WM_KEYUP nVirtKey:VK_HOME cRepeat:1 ScanCode:00 fExtended:0
fAltDown:0 fRepeat:1 fUp:1
<00019> 001B084E P WM_KEYDOWN nVirtKey:VK_SHIFT cRepeat:1 ScanCode:00 fExtended:0
fAltDown:0 fRepeat:0 fUp:0
<00020> 001B084E P WM_KEYUP nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0
fAltDown:0 fRepeat:1 fUp:1
<00021> 001B084E P WM_KEYDOWN nVirtKey:VK_END cRepeat:1 ScanCode:00 fExtended:0
fAltDown:0 fRepeat:0 fUp:0
<00022> 001B084E P WM_KEYUP nVirtKey:VK_END cRepeat:1 ScanCode:00 fExtended:0
fAltDown:0 fRepeat:1 fUp:1
<00023> 001B084E P WM_KEYDOWN nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0
fAltDown:0 fRepeat:0 fUp:0
<00024> 001B084E P WM_KEYUP nVirtKey:VK_SHIFT cRepeat:1 ScanCode:00 fExtended:0
fAltDown:0 fRepeat:1 fUp:1

If I use VBA.SendKeys, I get this:

   Text1_KeyDown(36, 0)
   Text1_KeyUp(36, 0)
   Text1_KeyDown(16, 1)
   Text1_KeyDown(35, 1)
   Text1_KeyUp(35, 1)
   Text1_KeyUp(16, 0)
   Text1_KeyDown(144, 0)
   Text1_KeyUp(144, 0)
   Text1_KeyDown(144, 0)
   Text1_KeyUp(144, 0)

What the heck's keycode 144?

Thanks much...   Karl
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
15 Nov 2007 6:15 PM
Bob Butler
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:egYLZ%236JIHA.4228@TK2MSFTNGP02.phx.gbl...
> Bob Butler wrote:
>>> I tried it and can't get it to fail (using Vista).  It highlight
>>> perfectly.
>
> Argh!

That about sums it up.  I tried sending the OEMScanCode instead and tried
using keybd_event directly.  In all cases under earlier OS versions an extra
shift-down or shift-up is inserted somewhere along the line whenever a
keycode like END is adjacent to it.  I can send "+(abc)" just fine and get
"[SHIFT]ABC[shift]" but "+{END}" always gives me 6 events instead of 4.

Is SendKeys using SendMessage or PostMessage?  I've searched and found
several references to the problem with keybd_event but no responses and no
acknowledgment that it is a bug.  Under Vista it works as I'd expect so
something got fixed. I don't know how SendKeys is getting around it.

>
> What the heck's keycode 144?

Haven't tracked that one down yet, not that I've spent a lot of time
looking.
Author
15 Nov 2007 6:47 PM
Karl E. Peterson
Bob Butler wrote:
> "Karl E. Peterson" <k***@mvps.org> wrote ...
>> Bob Butler wrote:
>>>> I tried it and can't get it to fail (using Vista).  It highlight
>>>> perfectly.
>>
>> Argh!
>
> That about sums it up.

But wait!  There's more!  :-(

I fired up VMs of Vista and W2K.  My sample worked just fine in W2K and behaved in
Vista just as it did on my base XP system.  WTF?

I stuck the code and EXE that I'm using here:

   http://vb.mvps.org/samples/code/SendInput.zip

in case anyone would like to try it?

> I tried sending the OEMScanCode instead and tried
> using keybd_event directly.  In all cases under earlier OS versions an extra
> shift-down or shift-up is inserted somewhere along the line whenever a
> keycode like END is adjacent to it.  I can send "+(abc)" just fine and get
> "[SHIFT]ABC[shift]" but "+{END}" always gives me 6 events instead of 4.

<grumble>  Yep.

> Is SendKeys using SendMessage or PostMessage?

Appears to be PostMessage.

> I've searched and found
> several references to the problem with keybd_event but no responses and no
> acknowledgment that it is a bug.  Under Vista it works as I'd expect so
> something got fixed. I don't know how SendKeys is getting around it.

Well, not necessarily.  It's definitely not working for me, under Vista.  Fwiw,
here's the matrix that I'm seeing, when I pass "{home}+{end}" to SendInput and
SendKeys in various OSes:

              SendInput      SendKeys
   Vista         NO             NO
   XP/SP2        NO            YES
   2000         YES            YES

:-(

>> What the heck's keycode 144?
>
> Haven't tracked that one down yet, not that I've spent a lot of time
> looking.

Weird, huh?
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
15 Nov 2007 6:51 PM
Randy Birch
The exe works perfectly on my XP system at work.

Show quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:e8lTzf7JIHA.2064@TK2MSFTNGP06.phx.gbl...
> Bob Butler wrote:
>> "Karl E. Peterson" <k***@mvps.org> wrote ...
>>> Bob Butler wrote:
>>>>> I tried it and can't get it to fail (using Vista).  It highlight
>>>>> perfectly.
>>>
>>> Argh!
>>
>> That about sums it up.
>
> But wait!  There's more!  :-(
>
> I fired up VMs of Vista and W2K.  My sample worked just fine in W2K and
> behaved in Vista just as it did on my base XP system.  WTF?
>
> I stuck the code and EXE that I'm using here:
>
>   http://vb.mvps.org/samples/code/SendInput.zip
>
> in case anyone would like to try it?
>
>> I tried sending the OEMScanCode instead and tried
>> using keybd_event directly.  In all cases under earlier OS versions an
>> extra
>> shift-down or shift-up is inserted somewhere along the line whenever a
>> keycode like END is adjacent to it.  I can send "+(abc)" just fine and
>> get
>> "[SHIFT]ABC[shift]" but "+{END}" always gives me 6 events instead of 4.
>
> <grumble>  Yep.
>
>> Is SendKeys using SendMessage or PostMessage?
>
> Appears to be PostMessage.
>
>> I've searched and found
>> several references to the problem with keybd_event but no responses and
>> no
>> acknowledgment that it is a bug.  Under Vista it works as I'd expect so
>> something got fixed. I don't know how SendKeys is getting around it.
>
> Well, not necessarily.  It's definitely not working for me, under Vista.
> Fwiw, here's the matrix that I'm seeing, when I pass "{home}+{end}" to
> SendInput and SendKeys in various OSes:
>
>              SendInput      SendKeys
>   Vista         NO             NO
>   XP/SP2        NO            YES
>   2000         YES            YES
>
> :-(
>
>>> What the heck's keycode 144?
>>
>> Haven't tracked that one down yet, not that I've spent a lot of time
>> looking.
>
> Weird, huh?
> --
> .NET: It's About Trust!
> http://vfred.mvps.org
>
Author
15 Nov 2007 6:57 PM
Karl E. Peterson
Randy Birch wrote:
> The exe works perfectly on my XP system at work.

GRRRRRRRRR!!!   SP1 or SP2?  (My money's on the former.)

Thanks!
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
15 Nov 2007 7:10 PM
Randy Birch
SP2.  I take my cappuccino with chocolate, please.

Show quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:ulgkjl7JIHA.3848@TK2MSFTNGP05.phx.gbl...
> Randy Birch wrote:
>> The exe works perfectly on my XP system at work.
>
> GRRRRRRRRR!!!   SP1 or SP2?  (My money's on the former.)
>
> Thanks!
> --
> .NET: It's About Trust!
> http://vfred.mvps.org
>
Author
15 Nov 2007 7:22 PM
Karl E. Peterson
Randy Birch wrote:
> "Karl E. Peterson" <k***@mvps.org> wrote ...
>> Randy Birch wrote:
>>> The exe works perfectly on my XP system at work.
>>
>> GRRRRRRRRR!!!   SP1 or SP2?  (My money's on the former.)
>
> SP2.  I take my cappuccino with chocolate, please.

Not the healthiest choice, but I can respect that. <G>

Okay, that's just friggin' weird.  Time for me to reboot?  What would cause it to
work on one system, but not another?

Fwiw, I just tried it on the mvps server (2003/SP1), and it's not working there
either, though standard SendKeys is.
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
15 Nov 2007 7:37 PM
Randy Birch
I can try the sample code on my vista and XP no-SP vm's tonight.  FWIW.
Can't run the code here on XP 'cause they don't trust me around development
tools. <g>


Show quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:eK94Tz7JIHA.4808@TK2MSFTNGP05.phx.gbl...
> Randy Birch wrote:
>> "Karl E. Peterson" <k***@mvps.org> wrote ...
>>> Randy Birch wrote:
>>>> The exe works perfectly on my XP system at work.
>>>
>>> GRRRRRRRRR!!!   SP1 or SP2?  (My money's on the former.)
>>
>> SP2.  I take my cappuccino with chocolate, please.
>
> Not the healthiest choice, but I can respect that. <G>
>
> Okay, that's just friggin' weird.  Time for me to reboot?  What would
> cause it to work on one system, but not another?
>
> Fwiw, I just tried it on the mvps server (2003/SP1), and it's not working
> there either, though standard SendKeys is.
> --
> .NET: It's About Trust!
> http://vfred.mvps.org
>
Author
15 Nov 2007 8:10 PM
Karl E. Peterson
Randy Birch wrote:
> I can try the sample code on my vista and XP no-SP vm's tonight.  FWIW.
> Can't run the code here on XP 'cause they don't trust me around development
> tools. <g>

LOL!
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
15 Nov 2007 9:27 PM
Karl E. Peterson
Karl E. Peterson wrote:
> Hey, I'm cobbling together a little utility here, and thought I'd use it as an
> excuse to come up to speed with SendInput.  What I can't really seem to find are
> any intelligible samples out there for this function.  Am I missing something
> really obvious, or did this one just pass the ClassicVB crowd by?

Solved the problem of the shifted-cursor keys!  Free clue found here:

   http://www.xtremevbtalk.com/archive/index.php/t-203863.html

D'oh!!!

Seemingly fully-functional sample now available here:

   http://vb.mvps.org/samples/code/SendInput.zip

Hope to have a description ready soon, and would prefer future links point, here:

   http://vb.mvps.org/samples/SendInput

Thanks...   Karl
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
15 Nov 2007 10:32 PM
Bob Butler
Show quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:eqbTX58JIHA.4712@TK2MSFTNGP04.phx.gbl...
> Karl E. Peterson wrote:
>> Hey, I'm cobbling together a little utility here, and thought I'd use it
>> as an
>> excuse to come up to speed with SendInput.  What I can't really seem to
>> find are
>> any intelligible samples out there for this function.  Am I missing
>> something
>> really obvious, or did this one just pass the ClassicVB crowd by?
>
> Solved the problem of the shifted-cursor keys!  Free clue found here:
>
>   http://www.xtremevbtalk.com/archive/index.php/t-203863.html

Yep, adding the extendedkey flag fixed it on my win2k box and left vista
untouched

I wonder if a WaitForInputIdle call would be a reasonable "Wait"
equivalent...
Author
15 Nov 2007 11:20 PM
Randy Birch
Hi Karl ...

Results of test at home:

------------------------------
EXE - Vista SP0
------------------------------
Code: {home}+{end}
SendInput:  NO (no text selected)
SendKeys:   NO (and no UAC error)

Code: {home}+{end}Testing123+(123)
SendInput:   YES ("Testing123!@#" sent to tbox)
SendKeys:    YES

------------------------------
EXE - XP SP2
------------------------------
Code: {home}+{end}
SendInput  YES (text selected)
SendKeys   YES

Code: {home}+{end}Testing123+(123)
SendInput:  YES ("Testing123!@#" sent to tbox)
SendKeys:   YES
-----------------------------------------------------------------------------------------------
----------------------------------
IDE - Vista SP0
----------------------------------
Code: {home}+{end}
SendInput:  YES (text selected)
SendKeys    NO   (permission error)

Code: {home}+{end}Testing123+(123)
SendInput:  YES ("Testing123!@#" was sent to tbox)
SendKeys:   NO

Code: qwerty{home}+{end}
SendInput:  YES (printed text and selected)
SendKeys:  NO

----------------------------------
IDE - XP SP2
----------------------------------
Code: {home}+{end}
SendInput: YES (text selected)
SendKeys:  YES

Code: {home}+{end}Testing123+(123)
SendInput:  YES ("Testing123!@#" was sent to tbox)
SendKeys:   YES

Code: qwerty{home}+{end}
SendInput:  YES (printed text and selected)
SendKeys:   YES

--


Randy Birch
http://vbnet.mvps.org/

Please respond to the newsgroups so all can benefit.


"Karl E. Peterson" <k***@mvps.org> wrote in message
news:uHxveO8JIHA.4712@TK2MSFTNGP04.phx.gbl...
Randy Birch wrote:
> I can try the sample code on my vista and XP no-SP vm's tonight.  FWIW.
> Can't run the code here on XP 'cause they don't trust me around
> development
> tools. <g>

LOL!
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
15 Nov 2007 11:22 PM
Karl E. Peterson
Bob Butler wrote:
Show quote
> "Karl E. Peterson" <k***@mvps.org> wrote in message
> news:eqbTX58JIHA.4712@TK2MSFTNGP04.phx.gbl...
>> Karl E. Peterson wrote:
>>> Hey, I'm cobbling together a little utility here, and thought I'd use it as an
>>> excuse to come up to speed with SendInput.  What I can't really seem to find are
>>> any intelligible samples out there for this function.  Am I missing something
>>> really obvious, or did this one just pass the ClassicVB crowd by?
>>
>> Solved the problem of the shifted-cursor keys!  Free clue found here:
>>
>>   http://www.xtremevbtalk.com/archive/index.php/t-203863.html
>
> Yep, adding the extendedkey flag fixed it on my win2k box and left vista
> untouched

Very cool.  :-)

> I wonder if a WaitForInputIdle call would be a reasonable "Wait"
> equivalent...

Well, I'd think not, for a handful of reasons.  Mainly, it requires a process
handle, and SendKeys really shouldn't care about that.  But it's also been there
since VB1, and there wasn't such a call in Win16, was there?  Also, I've seen no
detectable difference in behavior, using that parameter, in well over 10-15 years
now.

I actually wonder if it does go back to a very early implementation, that maybe it
was the difference between SendMessage and PostMessage?  But that later on, they
began using more complicated (delicate) methods like journal hooks, and whatnot, and
now it's just a worthless appendage?

Sure wish I had the skill to read ASM dumps from VB!  Oughta be somewhat clear, from
one of those, huh?
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
15 Nov 2007 11:23 PM
Karl E. Peterson
Randy Birch wrote:
> Hi Karl ...
>
> Results of test at home:

Gotta ask, did you try the new code that uses the KEYEVENTF_EXTENDEDKEY for cursor
keys?  Given the inconsistent results, I hope not. <g>

  http://vb.mvps.org/samples/SendInput

Thanks...   Karl


Show quote
> ------------------------------
> EXE - Vista SP0
> ------------------------------
> Code: {home}+{end}
> SendInput:  NO (no text selected)
> SendKeys:   NO (and no UAC error)
>
> Code: {home}+{end}Testing123+(123)
> SendInput:   YES ("Testing123!@#" sent to tbox)
> SendKeys:    YES
>
> ------------------------------
> EXE - XP SP2
> ------------------------------
> Code: {home}+{end}
> SendInput  YES (text selected)
> SendKeys   YES
>
> Code: {home}+{end}Testing123+(123)
> SendInput:  YES ("Testing123!@#" sent to tbox)
> SendKeys:   YES
> -----------------------------------------------------------------------------------------------
> ----------------------------------
> IDE - Vista SP0
> ----------------------------------
> Code: {home}+{end}
> SendInput:  YES (text selected)
> SendKeys    NO   (permission error)
>
> Code: {home}+{end}Testing123+(123)
> SendInput:  YES ("Testing123!@#" was sent to tbox)
> SendKeys:   NO
>
> Code: qwerty{home}+{end}
> SendInput:  YES (printed text and selected)
> SendKeys:  NO
>
> ----------------------------------
> IDE - XP SP2
> ----------------------------------
> Code: {home}+{end}
> SendInput: YES (text selected)
> SendKeys:  YES
>
> Code: {home}+{end}Testing123+(123)
> SendInput:  YES ("Testing123!@#" was sent to tbox)
> SendKeys:   YES
>
> Code: qwerty{home}+{end}
> SendInput:  YES (printed text and selected)
> SendKeys:   YES
>
> --
>
>
> Randy Birch
> http://vbnet.mvps.org/
>
> Please respond to the newsgroups so all can benefit.
>
>
> "Karl E. Peterson" <k***@mvps.org> wrote in message
> news:uHxveO8JIHA.4712@TK2MSFTNGP04.phx.gbl...
> Randy Birch wrote:
>> I can try the sample code on my vista and XP no-SP vm's tonight.  FWIW.
>> Can't run the code here on XP 'cause they don't trust me around
>> development
>> tools. <g>
>
> LOL!

--
..NET: It's About Trust!
http://vfred.mvps.org
Author
15 Nov 2007 11:35 PM
Randy Birch
Might have been - whatever you had on the site 15 minutes before I posted.
I didn't keep a copy of the code from earlier this afternoon.

--


Randy Birch
http://vbnet.mvps.org/

Please respond to the newsgroups so all can benefit.


"Karl E. Peterson" <k***@mvps.org> wrote in message
news:OglTT69JIHA.5468@TK2MSFTNGP05.phx.gbl...
Randy Birch wrote:
> Hi Karl ...
>
> Results of test at home:

Gotta ask, did you try the new code that uses the KEYEVENTF_EXTENDEDKEY for
cursor
keys?  Given the inconsistent results, I hope not. <g>

  http://vb.mvps.org/samples/SendInput

Thanks...   Karl


Show quote
> ------------------------------
> EXE - Vista SP0
> ------------------------------
> Code: {home}+{end}
> SendInput:  NO (no text selected)
> SendKeys:   NO (and no UAC error)
>
> Code: {home}+{end}Testing123+(123)
> SendInput:   YES ("Testing123!@#" sent to tbox)
> SendKeys:    YES
>
> ------------------------------
> EXE - XP SP2
> ------------------------------
> Code: {home}+{end}
> SendInput  YES (text selected)
> SendKeys   YES
>
> Code: {home}+{end}Testing123+(123)
> SendInput:  YES ("Testing123!@#" sent to tbox)
> SendKeys:   YES
> -----------------------------------------------------------------------------------------------
> ----------------------------------
> IDE - Vista SP0
> ----------------------------------
> Code: {home}+{end}
> SendInput:  YES (text selected)
> SendKeys    NO   (permission error)
>
> Code: {home}+{end}Testing123+(123)
> SendInput:  YES ("Testing123!@#" was sent to tbox)
> SendKeys:   NO
>
> Code: qwerty{home}+{end}
> SendInput:  YES (printed text and selected)
> SendKeys:  NO
>
> ----------------------------------
> IDE - XP SP2
> ----------------------------------
> Code: {home}+{end}
> SendInput: YES (text selected)
> SendKeys:  YES
>
> Code: {home}+{end}Testing123+(123)
> SendInput:  YES ("Testing123!@#" was sent to tbox)
> SendKeys:   YES
>
> Code: qwerty{home}+{end}
> SendInput:  YES (printed text and selected)
> SendKeys:   YES
>
> --
>
>
> Randy Birch
> http://vbnet.mvps.org/
>
> Please respond to the newsgroups so all can benefit.
>
>
> "Karl E. Peterson" <k***@mvps.org> wrote in message
> news:uHxveO8JIHA.4712@TK2MSFTNGP04.phx.gbl...
> Randy Birch wrote:
>> I can try the sample code on my vista and XP no-SP vm's tonight.  FWIW.
>> Can't run the code here on XP 'cause they don't trust me around
>> development
>> tools. <g>
>
> LOL!

--
..NET: It's About Trust!
http://vfred.mvps.org
Author
15 Nov 2007 11:37 PM
Randy Birch
I did mean to mention that the EXE and IDE method that worked on Vista
filled the tb like molasses.  Could pretty well see each letter being added
to the sentence.

--


Randy Birch
http://vbnet.mvps.org/

Please respond to the newsgroups so all can benefit.


"Karl E. Peterson" <k***@mvps.org> wrote in message
news:OglTT69JIHA.5468@TK2MSFTNGP05.phx.gbl...
Randy Birch wrote:
> Hi Karl ...
>
> Results of test at home:

Gotta ask, did you try the new code that uses the KEYEVENTF_EXTENDEDKEY for
cursor
keys?  Given the inconsistent results, I hope not. <g>

  http://vb.mvps.org/samples/SendInput

Thanks...   Karl


Show quote
> ------------------------------
> EXE - Vista SP0
> ------------------------------
> Code: {home}+{end}
> SendInput:  NO (no text selected)
> SendKeys:   NO (and no UAC error)
>
> Code: {home}+{end}Testing123+(123)
> SendInput:   YES ("Testing123!@#" sent to tbox)
> SendKeys:    YES
>
> ------------------------------
> EXE - XP SP2
> ------------------------------
> Code: {home}+{end}
> SendInput  YES (text selected)
> SendKeys   YES
>
> Code: {home}+{end}Testing123+(123)
> SendInput:  YES ("Testing123!@#" sent to tbox)
> SendKeys:   YES
> -----------------------------------------------------------------------------------------------
> ----------------------------------
> IDE - Vista SP0
> ----------------------------------
> Code: {home}+{end}
> SendInput:  YES (text selected)
> SendKeys    NO   (permission error)
>
> Code: {home}+{end}Testing123+(123)
> SendInput:  YES ("Testing123!@#" was sent to tbox)
> SendKeys:   NO
>
> Code: qwerty{home}+{end}
> SendInput:  YES (printed text and selected)
> SendKeys:  NO
>
> ----------------------------------
> IDE - XP SP2
> ----------------------------------
> Code: {home}+{end}
> SendInput: YES (text selected)
> SendKeys:  YES
>
> Code: {home}+{end}Testing123+(123)
> SendInput:  YES ("Testing123!@#" was sent to tbox)
> SendKeys:   YES
>
> Code: qwerty{home}+{end}
> SendInput:  YES (printed text and selected)
> SendKeys:   YES
>
> --
>
>
> Randy Birch
> http://vbnet.mvps.org/
>
> Please respond to the newsgroups so all can benefit.
>
>
> "Karl E. Peterson" <k***@mvps.org> wrote in message
> news:uHxveO8JIHA.4712@TK2MSFTNGP04.phx.gbl...
> Randy Birch wrote:
>> I can try the sample code on my vista and XP no-SP vm's tonight.  FWIW.
>> Can't run the code here on XP 'cause they don't trust me around
>> development
>> tools. <g>
>
> LOL!

--
..NET: It's About Trust!
http://vfred.mvps.org
Author
16 Nov 2007 12:44 AM
Karl E. Peterson
Randy Birch wrote:
> I did mean to mention that the EXE and IDE method that worked on Vista
> filled the tb like molasses.  Could pretty well see each letter being added
> to the sentence.

Damm!  Another anomalous result!  You still running Vista on a Mac? <gd&rvvf>
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
16 Nov 2007 11:08 PM
Randy Birch
Yes  - for now - but to Vista and XP it looks like its own box.

--


Randy Birch
http://vbnet.mvps.org/

Please respond to the newsgroups so all can benefit.


"Karl E. Peterson" <k***@mvps.org> wrote in message
news:eC13mn%23JIHA.5684@TK2MSFTNGP06.phx.gbl...
Randy Birch wrote:
> I did mean to mention that the EXE and IDE method that worked on Vista
> filled the tb like molasses.  Could pretty well see each letter being
> added
> to the sentence.

Damm!  Another anomalous result!  You still running Vista on a Mac?
<gd&rvvf>
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
16 Nov 2007 12:43 AM
Karl E. Peterson
Randy Birch wrote:
> Might have been - whatever you had on the site 15 minutes before I posted.
> I didn't keep a copy of the code from earlier this afternoon.

Hmmmmm...  I'm gonna have to assume you're nothing but an anomoly, then, *Larry*...
<gd&r>

Thanks...
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
16 Nov 2007 1:40 AM
Stefan Berglund
On Thu, 15 Nov 2007 18:37:41 -0500, "Randy Birch"
<rgb_removet***@mvps.org> wrote:
in <up7RFC#JIHA.5***@TK2MSFTNGP02.phx.gbl>

>I did mean to mention that the EXE and IDE method that worked on Vista
>filled the tb like molasses.  Could pretty well see each letter being added
>to the sentence.

Do you by any chance use a KVM switch to move from computer to computer?
I do and whenever I switch to a W2K box and then back to XP Pro the
keyboard repeat rate gets snockered.  I have to go into Control
Panel|Keyboard and drag the Repeat Rate slider from Fast to Slow and
then back to Fast again in order to get it back where I like it - real
fast.

---
Stefan Berglund
Author
16 Nov 2007 1:03 PM
Randy Birch
No, but I am using Vista and XP in virtual machines on an iMac, at least
until by blackbird arrives next month.

Show quote
"Stefan Berglund" <sorry.no.kool***@for.me> wrote in message
news:nvspj31fbn6timda96hu3035833g7upcfk@4ax.com...
> On Thu, 15 Nov 2007 18:37:41 -0500, "Randy Birch"
> <rgb_removet***@mvps.org> wrote:
> in <up7RFC#JIHA.5***@TK2MSFTNGP02.phx.gbl>
>
>>I did mean to mention that the EXE and IDE method that worked on Vista
>>filled the tb like molasses.  Could pretty well see each letter being
>>added
>>to the sentence.
>
> Do you by any chance use a KVM switch to move from computer to computer?
> I do and whenever I switch to a W2K box and then back to XP Pro the
> keyboard repeat rate gets snockered.  I have to go into Control
> Panel|Keyboard and drag the Repeat Rate slider from Fast to Slow and
> then back to Fast again in order to get it back where I like it - real
> fast.
>
> ---
> Stefan Berglund
Author
16 Nov 2007 11:18 PM
Randy Birch
> then, *Larry*...


hmmmmmmmmm. 

--


Randy Birch
http://vbnet.mvps.org/

Please respond to the newsgroups so all can benefit.
Author
17 Nov 2007 1:59 AM
Karl E. Peterson
Randy Birch wrote:
>> then, *Larry*...
>
> hmmmmmmmmm.

Jest call me Daryll... <LOL>
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
17 Nov 2007 2:58 AM
Kevin Provance
Where's your other brother Daryll?

(If you didn't get it, it's a Newhart thing)

Show quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:eD8TI2LKIHA.5400@TK2MSFTNGP04.phx.gbl...
| Randy Birch wrote:
| >> then, *Larry*...
| >
| > hmmmmmmmmm.
|
| Jest call me Daryll... <LOL>
| --
| .NET: It's About Trust!
| http://vfred.mvps.org
|
|
Author
15 Nov 2007 11:39 PM
Bob Butler
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:eHSYa59JIHA.1184@TK2MSFTNGP04.phx.gbl...
<cut>
>> I wonder if a WaitForInputIdle call would be a reasonable "Wait"
>> equivalent...
>
> Well, I'd think not, for a handful of reasons.  Mainly, it requires a
> process handle, and SendKeys really shouldn't care about that.

I agree, just grasping at straws.  I seem to remember reading somewhere
along the line that the Wait parameter no longer did anything but was still
there for backward compatibility.  I can't find that now though.



BTW, I get an error opening the project in your zip file -- the file name of
the form is incorrect
Author
15 Nov 2007 11:50 PM
Kevin Provance
Karl -

Here are my results from your latest offering (using Randy's test criteria):

--------------------
IDE - XP SP2
--------------------
Code: {home}+{end}
SendInput: Yes (text selected)
SendKeys: Yes (text selected)

Code: {home}+{end}Testing123+(123)
SendInput: Yes ("Testing123!@#" sent to box)
SendKeys: Yes

Code: qwerty{home}+{end}
SendInput: Yes (printed text and selected)
SendKeys: Yes

--------------------
IDE - Vista Home Premium
--------------------
Code: {home}+{end}
SendInput: Yes (text selected)
SendKeys: No (permission denied)

Code: {home}+{end}Testing123+(123)
SendInput: Yes ("Testing123!@#" sent to box)
SendKeys: No (permission denied)

Code: qwerty{home}+{end}
SendInput: Yes (printed text and selected)
SendKeys: No (permission denied)

--------------------
EXE - XP SP2
--------------------
Code: {home}+{end}
SendInput: Yes (text selected)
SendKeys: Yes (text selected)

Code: {home}+{end}Testing123+(123)
SendInput: Yes ("Testing123!@#" sent to box)
SendKeys: Yes

Code: qwerty{home}+{end}
SendInput: Yes (printed text and selected)
SendKeys: Yes

--------------------
EXE - Vista Home Premium
--------------------
Code: {home}+{end}
SendInput: Yes (text selected)
SendKeys: Yes (text selected)

Code: {home}+{end}Testing123+(123)
SendInput: Yes ("Testing123!@#" sent to box)
SendKeys: Yes

Code: qwerty{home}+{end}
SendInput: Yes (printed text and selected)
SendKeys: Yes

Pretty much the same thing.  Don't know how much help that was, but those
are my results.

- Kev

Show quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:OglTT69JIHA.5468@TK2MSFTNGP05.phx.gbl...
| Randy Birch wrote:
| > Hi Karl ...
| >
| > Results of test at home:
|
| Gotta ask, did you try the new code that uses the KEYEVENTF_EXTENDEDKEY
for cursor
| keys?  Given the inconsistent results, I hope not. <g>
|
http://vb.mvps.org/samples/SendInput
|
| Thanks...   Karl
|
|
| > ------------------------------
| > EXE - Vista SP0
| > ------------------------------
| > Code: {home}+{end}
| > SendInput:  NO (no text selected)
| > SendKeys:   NO (and no UAC error)
| >
| > Code: {home}+{end}Testing123+(123)
| > SendInput:   YES ("Testing123!@#" sent to tbox)
| > SendKeys:    YES
| >
| > ------------------------------
| > EXE - XP SP2
| > ------------------------------
| > Code: {home}+{end}
| > SendInput  YES (text selected)
| > SendKeys   YES
| >
| > Code: {home}+{end}Testing123+(123)
| > SendInput:  YES ("Testing123!@#" sent to tbox)
| > SendKeys:   YES
|
> -----------------------------------------------------------------------------------------------
| > ----------------------------------
| > IDE - Vista SP0
| > ----------------------------------
| > Code: {home}+{end}
| > SendInput:  YES (text selected)
| > SendKeys    NO   (permission error)
| >
| > Code: {home}+{end}Testing123+(123)
| > SendInput:  YES ("Testing123!@#" was sent to tbox)
| > SendKeys:   NO
| >
| > Code: qwerty{home}+{end}
| > SendInput:  YES (printed text and selected)
| > SendKeys:  NO
| >
| > ----------------------------------
| > IDE - XP SP2
| > ----------------------------------
| > Code: {home}+{end}
| > SendInput: YES (text selected)
| > SendKeys:  YES
| >
| > Code: {home}+{end}Testing123+(123)
| > SendInput:  YES ("Testing123!@#" was sent to tbox)
| > SendKeys:   YES
| >
| > Code: qwerty{home}+{end}
| > SendInput:  YES (printed text and selected)
| > SendKeys:   YES
| >
| > --
| >
| >
| > Randy Birch
| > http://vbnet.mvps.org/
| >
| > Please respond to the newsgroups so all can benefit.
| >
| >
| > "Karl E. Peterson" <k***@mvps.org> wrote in message
| > news:uHxveO8JIHA.4712@TK2MSFTNGP04.phx.gbl...
| > Randy Birch wrote:
| >> I can try the sample code on my vista and XP no-SP vm's tonight.  FWIW.
| >> Can't run the code here on XP 'cause they don't trust me around
| >> development
| >> tools. <g>
| >
| > LOL!
|
| --
| .NET: It's About Trust!
| http://vfred.mvps.org
|
|
Author
16 Nov 2007 12:46 AM
Karl E. Peterson
Kevin Provance wrote:
> Here are my results from your latest offering (using Randy's test criteria):

Those actually look like what I'd expect.  You?  Seems we whooped this one.  :-)

Thanks...   Karl
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
16 Nov 2007 2:38 AM
Kevin Provance
Yeah, it worked axactly as it should...and one couldn't ask for anything
more.  I may end up compiling this into a DLL (as I would be using it across
multiple projects) unless you have any strong objections.  I'll call it
kpSndKys.dll  ;-)

What's with the "we" stuff?  This was all you bro.  I just tagged along for
the ride and learned some new tricks, for which I thank you.  Excellent
work.

- Kev

Show quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:OpxAmo%23JIHA.1204@TK2MSFTNGP03.phx.gbl...
| Kevin Provance wrote:
| > Here are my results from your latest offering (using Randy's test
criteria):
|
| Those actually look like what I'd expect.  You?  Seems we whooped this
one.  :-)
|
| Thanks...   Karl
| --
| .NET: It's About Trust!
| http://vfred.mvps.org
|
|
Author
16 Nov 2007 6:11 PM
Karl E. Peterson
Kevin Provance wrote:
> Yeah, it worked axactly as it should...and one couldn't ask for anything
> more.  I may end up compiling this into a DLL (as I would be using it across
> multiple projects) unless you have any strong objections.  I'll call it
> kpSndKys.dll  ;-)

It's "out there" now, intended to be used - go for it!  Myself, I'd probably just
compile that module into anything that needed it.  Also probably change the the
subroutine name from MySendKeys to just SendKeys, so it'd override the native one.
The "rules" for native SendKeys are incredibly perverse.  I guess I'd never really
read them that closely before.  But I believe this one exactly replicates the native
in intent, if not actual outcome.  Which was, afterall, the goal. <g>

> What's with the "we" stuff?  This was all you bro.  I just tagged along for
> the ride and learned some new tricks, for which I thank you.  Excellent
> work.

:-)

Thanks...
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
19 Nov 2007 8:42 PM
Kevin Provance
Karl -

Follow up for you in case you are still monitoring this thread.  I ran your
project in IDE and EXE under Windows98 SE using Randy's test criteria and
everything was a success...FWIW.  <g>

- Kev

Show quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:e1t9NwHKIHA.4272@TK2MSFTNGP06.phx.gbl...
| Kevin Provance wrote:
| > Yeah, it worked axactly as it should...and one couldn't ask for anything
| > more.  I may end up compiling this into a DLL (as I would be using it
across
| > multiple projects) unless you have any strong objections.  I'll call it
| > kpSndKys.dll  ;-)
|
| It's "out there" now, intended to be used - go for it!  Myself, I'd
probably just
| compile that module into anything that needed it.  Also probably change
the the
| subroutine name from MySendKeys to just SendKeys, so it'd override the
native one.
| The "rules" for native SendKeys are incredibly perverse.  I guess I'd
never really
| read them that closely before.  But I believe this one exactly replicates
the native
| in intent, if not actual outcome.  Which was, afterall, the goal. <g>
|
| > What's with the "we" stuff?  This was all you bro.  I just tagged along
for
| > the ride and learned some new tricks, for which I thank you.  Excellent
| > work.
|
| :-)
|
| Thanks...
| --
| .NET: It's About Trust!
| http://vfred.mvps.org
|
|
Author
19 Nov 2007 11:44 PM
Karl E. Peterson
Kevin Provance wrote:
> Follow up for you in case you are still monitoring this thread.  I ran your
> project in IDE and EXE under Windows98 SE using Randy's test criteria and
> everything was a success...FWIW.  <g>

Cool, thanks!  I didn't have a chance to even try on 9x...
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
16 Nov 2007 12:48 AM
Karl E. Peterson
Bob Butler wrote:
> "Karl E. Peterson" <k***@mvps.org> wrote in message
> news:eHSYa59JIHA.1184@TK2MSFTNGP04.phx.gbl...
> <cut>
>>> I wonder if a WaitForInputIdle call would be a reasonable "Wait"
>>> equivalent...
>>
>> Well, I'd think not, for a handful of reasons.  Mainly, it requires a
>> process handle, and SendKeys really shouldn't care about that.
>
> I agree, just grasping at straws.  I seem to remember reading somewhere
> along the line that the Wait parameter no longer did anything but was still
> there for backward compatibility.  I can't find that now though.

I'd love to find that.  It'd totally justify me ignoring it too. <g>

(Certainly corresponds to my observations, though!)

> BTW, I get an error opening the project in your zip file -- the file name of
> the form is incorrect

Aw, jeeez...  Sorry about that!  I just replaced it with one that isn't all hosed.
Might've explained some of Randy's issues, too.  Trying to get way too much done
here today.

Thanks...   Karl
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
16 Nov 2007 1:06 AM
Bob Butler
Show quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:Otjnpp%23JIHA.5764@TK2MSFTNGP06.phx.gbl...
> Bob Butler wrote:
>> "Karl E. Peterson" <k***@mvps.org> wrote in message
>> news:eHSYa59JIHA.1184@TK2MSFTNGP04.phx.gbl...
>> <cut>
>>>> I wonder if a WaitForInputIdle call would be a reasonable "Wait"
>>>> equivalent...
>>>
>>> Well, I'd think not, for a handful of reasons.  Mainly, it requires a
>>> process handle, and SendKeys really shouldn't care about that.
>>
>> I agree, just grasping at straws.  I seem to remember reading somewhere
>> along the line that the Wait parameter no longer did anything but was
>> still
>> there for backward compatibility.  I can't find that now though.
>
> I'd love to find that.  It'd totally justify me ignoring it too. <g>
>
> (Certainly corresponds to my observations, though!)

I found what I was remembering but it was for VB Script, not VB
Author
16 Nov 2007 1:18 AM
Karl E. Peterson
Bob Butler wrote:
Show quote
> "Karl E. Peterson" <k***@mvps.org> wrote...
>> Bob Butler wrote:
>>> "Karl E. Peterson" <k***@mvps.org> wrote in message
>>> news:eHSYa59JIHA.1184@TK2MSFTNGP04.phx.gbl...
>>> <cut>
>>>>> I wonder if a WaitForInputIdle call would be a reasonable "Wait"
>>>>> equivalent...
>>>>
>>>> Well, I'd think not, for a handful of reasons.  Mainly, it requires a
>>>> process handle, and SendKeys really shouldn't care about that.
>>>
>>> I agree, just grasping at straws.  I seem to remember reading somewhere
>>> along the line that the Wait parameter no longer did anything but was
>>> still
>>> there for backward compatibility.  I can't find that now though.
>>
>> I'd love to find that.  It'd totally justify me ignoring it too. <g>
>>
>> (Certainly corresponds to my observations, though!)
>
> I found what I was remembering but it was for VB Script, not VB

Mmmm, yeah, they removed it altogether there, didn't they?
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
16 Nov 2007 1:34 AM
Bob Butler
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:e%23cph6%23JIHA.3400@TK2MSFTNGP03.phx.gbl...
>> I found what I was remembering but it was for VB Script, not VB
>
> Mmmm, yeah, they removed it altogether there, didn't they?

not quite

set s=createobject("WScript.Shell")
s.AppActivate "Untitled - Notepad"
s.SendKeys "abc",true
Author
16 Nov 2007 1:41 AM
Karl E. Peterson
Bob Butler wrote:
> "Karl E. Peterson" <k***@mvps.org> wrote in message
> news:e%23cph6%23JIHA.3400@TK2MSFTNGP03.phx.gbl...
>>> I found what I was remembering but it was for VB Script, not VB
>>
>> Mmmm, yeah, they removed it altogether there, didn't they?
>
> not quite
>
> set s=createobject("WScript.Shell")
> s.AppActivate "Untitled - Notepad"
> s.SendKeys "abc",true

Yeah, that looks familiar, too.  Hmmm, I think this is what I'd seen recently, that
made me say that:

http://msdn2.microsoft.com/en-us/library/8c6yea83.aspx
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
16 Nov 2007 2:02 AM
Bob Butler
Show quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:O03TDH$JIHA.5116@TK2MSFTNGP03.phx.gbl...
> Bob Butler wrote:
>> "Karl E. Peterson" <k***@mvps.org> wrote in message
>> news:e%23cph6%23JIHA.3400@TK2MSFTNGP03.phx.gbl...
>>>> I found what I was remembering but it was for VB Script, not VB
>>>
>>> Mmmm, yeah, they removed it altogether there, didn't they?
>>
>> not quite
>>
>> set s=createobject("WScript.Shell")
>> s.AppActivate "Untitled - Notepad"
>> s.SendKeys "abc",true
>
> Yeah, that looks familiar, too.  Hmmm, I think this is what I'd seen
> recently, that made me say that:
>
> http://msdn2.microsoft.com/en-us/library/8c6yea83.aspx

Yeah, they took the optional second parameter out of the documentation but
it's still defined, just ignored.
Author
16 Nov 2007 2:10 AM
Karl E. Peterson
Bob Butler wrote:
Show quote
> "Karl E. Peterson" <k***@mvps.org> wrote in message
> news:O03TDH$JIHA.5116@TK2MSFTNGP03.phx.gbl...
>> Bob Butler wrote:
>>> "Karl E. Peterson" <k***@mvps.org> wrote in message
>>> news:e%23cph6%23JIHA.3400@TK2MSFTNGP03.phx.gbl...
>>>>> I found what I was remembering but it was for VB Script, not VB
>>>>
>>>> Mmmm, yeah, they removed it altogether there, didn't they?
>>>
>>> not quite
>>>
>>> set s=createobject("WScript.Shell")
>>> s.AppActivate "Untitled - Notepad"
>>> s.SendKeys "abc",true
>>
>> Yeah, that looks familiar, too.  Hmmm, I think this is what I'd seen
>> recently, that made me say that:
>>
>> http://msdn2.microsoft.com/en-us/library/8c6yea83.aspx
>
> Yeah, they took the optional second parameter out of the documentation but
> it's still defined, just ignored.

Gotta like that.  :-)
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
16 Nov 2007 2:14 AM
Bob Butler
Show quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:O46RmX$JIHA.3916@TK2MSFTNGP02.phx.gbl...
> Bob Butler wrote:
>> "Karl E. Peterson" <k***@mvps.org> wrote in message
>> news:O03TDH$JIHA.5116@TK2MSFTNGP03.phx.gbl...
>>> Bob Butler wrote:
>>>> "Karl E. Peterson" <k***@mvps.org> wrote in message
>>>> news:e%23cph6%23JIHA.3400@TK2MSFTNGP03.phx.gbl...
>>>>>> I found what I was remembering but it was for VB Script, not VB
>>>>>
>>>>> Mmmm, yeah, they removed it altogether there, didn't they?
>>>>
>>>> not quite
>>>>
>>>> set s=createobject("WScript.Shell")
>>>> s.AppActivate "Untitled - Notepad"
>>>> s.SendKeys "abc",true
>>>
>>> Yeah, that looks familiar, too.  Hmmm, I think this is what I'd seen
>>> recently, that made me say that:
>>>
>>> http://msdn2.microsoft.com/en-us/library/8c6yea83.aspx
>>
>> Yeah, they took the optional second parameter out of the documentation
>> but
>> it's still defined, just ignored.
>
> Gotta like that.  :-)

So your code is a VB6 replacement for the VBScript Sendkeys function!
Author
16 Nov 2007 6:13 PM
Karl E. Peterson
Bob Butler wrote:
Show quote
> "Karl E. Peterson" <k***@mvps.org> wrote ...
>> Bob Butler wrote:
>>> "Karl E. Peterson" <k***@mvps.org> wrote ...
>>>> Bob Butler wrote:
>>>>> "Karl E. Peterson" <k***@mvps.org> wrote in message
>>>>> news:e%23cph6%23JIHA.3400@TK2MSFTNGP03.phx.gbl...
>>>>>>> I found what I was remembering but it was for VB Script, not VB
>>>>>>
>>>>>> Mmmm, yeah, they removed it altogether there, didn't they?
>>>>>
>>>>> not quite
>>>>>
>>>>> set s=createobject("WScript.Shell")
>>>>> s.AppActivate "Untitled - Notepad"
>>>>> s.SendKeys "abc",true
>>>>
>>>> Yeah, that looks familiar, too.  Hmmm, I think this is what I'd seen
>>>> recently, that made me say that:
>>>>
>>>> http://msdn2.microsoft.com/en-us/library/8c6yea83.aspx
>>>
>>> Yeah, they took the optional second parameter out of the documentation
>>> but
>>> it's still defined, just ignored.
>>
>> Gotta like that.  :-)
>
> So your code is a VB6 replacement for the VBScript Sendkeys function!

Y'know, it's weird.  Microsoft told me they'd fixed WSH, but didn't want folks using
it because "there might be language issues."  They've fixed Office 2007 VBA, but not
Office 2003, because it's not the latest so it shouldn't give an equally good
experience.  (No kidding!)  They've fixed VB6, but only the runtime and not the
editor.  VB5 can pound sand, as far as they care.  Yeah, I think this code can do a
decent stand-in in a *lot* of places, perhaps even from VBS! <g>
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
16 Nov 2007 1:05 PM
Randy Birch
I got the same message but added the form to the project manually and it
ran.

Show quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:Otjnpp%23JIHA.5764@TK2MSFTNGP06.phx.gbl...
> Bob Butler wrote:
>> "Karl E. Peterson" <k***@mvps.org> wrote in message
>> news:eHSYa59JIHA.1184@TK2MSFTNGP04.phx.gbl...
>> <cut>
>>>> I wonder if a WaitForInputIdle call would be a reasonable "Wait"
>>>> equivalent...
>>>
>>> Well, I'd think not, for a handful of reasons.  Mainly, it requires a
>>> process handle, and SendKeys really shouldn't care about that.
>>
>> I agree, just grasping at straws.  I seem to remember reading somewhere
>> along the line that the Wait parameter no longer did anything but was
>> still
>> there for backward compatibility.  I can't find that now though.
>
> I'd love to find that.  It'd totally justify me ignoring it too. <g>
>
> (Certainly corresponds to my observations, though!)
>
>> BTW, I get an error opening the project in your zip file -- the file name
>> of
>> the form is incorrect
>
> Aw, jeeez...  Sorry about that!  I just replaced it with one that isn't
> all hosed. Might've explained some of Randy's issues, too.  Trying to get
> way too much done here today.
>
> Thanks...   Karl
> --
> .NET: It's About Trust!
> http://vfred.mvps.org
>
Author
16 Nov 2007 6:15 PM
Karl E. Peterson
Randy Birch wrote:
> I got the same message but added the form to the project manually and it
> ran.

Should be all fixed, now.  (Stupid "Freshen" in WinZip didn't know I'd changed the
friggin' FRM's filename. <g>)
--
..NET: It's About Trust!
http://vfred.mvps.org

AddThis Social Bookmark Button