Page 1 of 1

ControlSend sends wrong characters

Posted: 12 Feb 2015, 23:20
by enthused
This was discussed here:
http://ahkscript.org/boards/viewtopic.php?f=5&t=6372

Code: Select all

#singleinstance,force
pr=notepad
sc=ahk_exe Notepad.exe

Gui,2: Add, Button, x10 y60 h25 w160 gA1,Write to Notepad
Gui,2: Show,x10 y10 h90 w200,Run_Notepad
Gui,2: Add, Edit, x10 y10 h40 w180 vE1, TEST1 `nTEST2 `n
return
2Guiclose:
exitapp

A1:
Gui,2: Submit, nohide
IfWinNotExist,%sc%
  {
  Run, %pr%,,,pid1
   WinWait,%SC%
   IfWinNotActive ,%SC%,,WinActivate,%SC%
      WinWaitActive,%SC%
  }
ControlSend,,%e1%,%sc%
return
Output:
TEST1 ; first send good
TEST2 ; first send good
tEST! ; second send note lower "T" and "!" instead of "1"
tEST@; second send note lower "T" and "@" instead of "2"
AHK 1.1.19.03 64 bit
Win 7 64 bit

Re: ControlSend sends wrong characters

Posted: 13 Feb 2015, 01:02
by lexikos
Sending keystrokes is inherently unreliable. This is not a bug. See below.
ControlSend wrote:The value of SetKeyDelay determines the speed at which keys are sent. If the target window does not receive the keystrokes reliably, try increasing the press duration via the second parameter of SetKeyDelay as in these examples:

Code: Select all

SetKeyDelay, 10, 10
SetKeyDelay, 0, 10
Note: ControlSend does not send characters. It sends keystroke messages.

Re: ControlSend sends wrong characters

Posted: 13 Feb 2015, 01:07
by enthused
Thank you Lexikos :D
Works well with: SetKeyDelay

edit:
lexikos wrote:Note: ControlSend does not send characters. It sends keystroke messages.
Thank you for the clarification. Important distinction.