Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

ControlSend multi-threaded (COM Interface)


  • Please log in to reply
3 replies to this topic
JackBaron
  • Members
  • 2 posts
  • Last active: May 21 2015 03:47 PM
  • Joined: 16 Feb 2015

Hi everybody,

 

I wrote here a little script that summarizes my problem. This script opens 2 Notepad windows to display strings simultaneously by ControlSend commands via the COM interface:

 

Run, Notepad.exe, , , notepad_pid1
Run, Notepad.exe, , , notepad_pid2
 
AhkThr1 := ComObjCreate("AutoHotkey.Script")
AhkThr2 := ComObjCreate("AutoHotkey.Script")
 
AhkThr1.ahktextdll("ControlSend, Edit1, abcdefghijklmabcdefghijklmabcdefghijklm, ahk_pid " . notepad_pid1 . "`nExitApp")
AhkThr2.ahktextdll("ControlSend, Edit1, NOPQRSTUVWXYZNOPQRSTUVWXYZNOPQRSTUVWXYZ, ahk_pid " . notepad_pid2 . "`nExitApp")
 
While AhkThr1.ahkReady() 
  Sleep, 100
While AhkThr2.ahkReady()
  Sleep, 100
 
 
The result that I obtained was :
(first notepad)       : abcDefghIjklmabcdefgHijklmabcDefghijklm
(second notepad) : NoPqRsTUvWxYzNoPqRsTuVWXYZNOPQRSTUVWxYz
 
As seen, uppercase and lowercase characters of the resulting strings are not compliant with the original ones (probably due to multi-threading).
Does anyone know how to get the right result?
 
Thank's in advance,
Jack


HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

;)

AhkThr1.ahktextdll("Control, EditPaste, abcdefghijklmabcdefghijklmabcdefghijklm,Edit1, ahk_pid " . notepad_pid1 . "`nExitApp")
AhkThr2.ahktextdll("Control, EditPaste, NOPQRSTUVWXYZNOPQRSTUVWXYZNOPQRSTUVWXYZ,Edit1, ahk_pid " . notepad_pid2 . "`nExitApp")


JackBaron
  • Members
  • 2 posts
  • Last active: May 21 2015 03:47 PM
  • Joined: 16 Feb 2015
Hi HotKeyIt,
 
I thank you for your quick response but the proposed workaround is not strictly equivalent to the ControlSend command of my script (I'm sorry to not have been more accurate in my first post). Actually, the Control command does not manage special keys nor the KeyDelay and I need them.
Please, reconsider my script prototype as:
 
Run, Notepad.exe, , , notepad_pid1
Run, Notepad.exe, , , notepad_pid2
 
AhkThr1 := ComObjCreate("AutoHotkey.Script")
AhkThr2 := ComObjCreate("AutoHotkey.Script")
 
AhkThr1.ahktextdll("SetKeyDelay, 15`nControlSend, Edit1, abcdefghijklmabcde{F5}fghijklmabcdefghijklm, ahk_pid " . notepad_pid1 . "`nExitApp")
AhkThr2.ahktextdll("SetKeyDelay, 30`nControlSend, Edit1, NOPQRSTUVWXYZNOPQR{F5}STUVWXYZNOPQRSTUVWXYZ, ahk_pid " . notepad_pid2 . "`nExitApp")
 
While AhkThr1.ahkReady() 
  Sleep, 100
While AhkThr2.ahkReady()
  Sleep, 100
 
It looks like keyboard states of the two threads are not fully independent.
Thanks again!
Jack


HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

No there is only one state for shift as far as I understand and that is the problem.

You will have to split the data and use ControlSend whenever needed and Control,EditPaste otherwise.

But even then you might need to send +{F5} which is going to be a problem.

Can you do ControlClick some button instead of {F5} or is there a menu?