Jump to content

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

How to send Ctrl+Keys to a specific window by Postmessage


  • Please log in to reply
5 replies to this topic
FantaSkyBlue
  • Members
  • 4 posts
  • Last active: May 01 2010 03:40 PM
  • Joined: 05 Mar 2010
The following code will continuously sed ESC + R to a specific Window Control. And after Press F12 to get the window control, the specific Window has no need to be activated (working background).
F12::
  ControlGetFocus, Var_Control, A
  WinGet, Var_WinTitle, ID, A
  Loop, 60
  {
  PostMessage, 0x100, 0x1B,, %Var_Control%, ahk_ID %Var_WinTitle% ; 0x100 = WM_KEYDOWN
  PostMessage, 0x102, 0x52,, %Var_Control%, ahk_ID %Var_WinTitle% ; 0X102 = WM_CHAR
  PostMessage, 0x101, 0x1B, 0xC0000000, %Var_Control%, ahk_ID %Var_WinTitle% ; 0X101 = WM_KEYUP
  Sleep, 1000
  }
Return

How sholud I write the code to send Ctrl+Keys to a specific Window by using Postmessage?

P.S: Use function ControlSend to send ^Keys will interfere with physical Ctrl key. So I used PostMessage.

jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006

P.S: Use function ControlSend to send ^Keys will interfere with physical Ctrl key. So I used PostMessage.

Did you read the remarks on the ControlSend page?

By default, modifier keystrokes (Control, Alt, Shift, and Win) are sent as they normally would be by the Send command... in some cases these modifier events may interfere with the active window... This can be avoided by explicitly sending modifier up and down events as in this example:
ControlSend, Edit1, {Alt down}f{Alt up}, Untitled - Notepad



FantaSkyBlue
  • Members
  • 4 posts
  • Last active: May 01 2010 03:40 PM
  • Joined: 05 Mar 2010
Thank you.
I've read that. But that didn't work perfectly since {ctrl down} would miss triggering sometimes.

jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006
I guess you'll have to use the Virtual-Key Code.

jl34567
  • Members
  • 262 posts
  • Last active: Nov 16 2011 11:44 PM
  • Joined: 03 Jan 2010
I've been trying to get the ControlClick to work on Flash content....no individual control names.....

It seems that it is clicking too fast, as the button is lighting up for a split second, indicating that cursor is over it or it is being pressed, but the button isn't registering the click.

It does however work if I set it to click 2-3 times......problem being that some of the buttons I need to press more than once.....so if I have my hotkey set to send 3 each time pressed, sometimes I will get 2 button presses, sometimes 3.....it's driving me nuts.

D/U commands have no effect.

I've been using the following as a workaround:
MouseGetPos
MouseClick
MouseMove

FantaSkyBlue
  • Members
  • 4 posts
  • Last active: May 01 2010 03:40 PM
  • Joined: 05 Mar 2010

I guess you'll have to use the Virtual-Key Code.


I've tried the following code. But it didn't work.
What the code did I saw was sending only "R".

F12::
  ControlGetFocus, Var_Control, A
  WinGet, Var_WinTitle, ID, A
  PostMessage, 0x100, 0x11,, %Var_Control%, ahk_ID %Var_WinTitle% ; 0x100 = WM_KEYDOWN ; 0x11 = Ctrl
  PostMessage, 0x102, 0x52,, %Var_Control%, ahk_ID %Var_WinTitle% ; 0X102 = WM_CHAR ; 0x52 = R
  PostMessage, 0x101, 0x11, 0xC0000000, %Var_Control%, ahk_ID %Var_WinTitle% ; 0X101 = WM_KEYUP
Return