K. Weber
K. Weber

Reputation: 2773

SendKeys.send is sending a key, but the application is not interpreting this key as a command

I'm using SendKeys to send key strokes to a program.

This is my code:

   If whandle <> 0 Then
        User32.SetForegroundWindow(whandle)
        System.Windows.Forms.SendKeys.Send("+")
    End If

(I tried also SendWait() instead of Send())

This is my window hierachy shown by Spy++:

Spy++ window hierachy

Althoug I can find window handle by title and loop through childs with User32.FindWindowEx, when debugging I just enter window handle as shown by spy++ (converting from hex to decimal) and I find that:

So I guess I have one of these problems:

  1. I'm doing something wrong with windows and subwindows (I don't really think this is happening as I tried all handles shown by Spy++).
  2. SendKey("+") is not exactly like pressing the "+" key when window is active and there is some difference.

After calling to User32.SetForegroundWindow(whandle) if I really press the "+" key the desired effect happens, which is a zoom in, but not when it's my program doing SendKeys. I tried also with other keys that produce commands, like Q or A (all of them simple keys and letters).

Upvotes: 1

Views: 417

Answers (1)

Mary
Mary

Reputation: 15081

From MS Docs

The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({}). For example, to specify the plus sign, use "{+}"

System.Windows.Forms.SendKeys.Send("{+}")

Upvotes: 2

Related Questions