PostMessage plz help Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
masheen
Posts: 294
Joined: 06 Dec 2016, 14:10

PostMessage plz help

23 Apr 2017, 09:45

How to post message CTRL+R or CTRL+left or CTRL+TAB
why my code dont work?


Code: Select all

SystemKeyPress("F5", "firefox.exe")

SystemKeyPress(key, proces){
	key = ctrl
	key1 = tab
	VK:=GetKeyVK(key)
	SC:=GetKeySC(key)
	VK1:=GetKeyVK(key1)
	SC1:=GetKeySC(key1)
	PostMessage, 0x104, %vk%, %sc%, , ahk_exe %proces%
	PostMessage, 0x100, %vk1%, %sc1%, , ahk_exe %proces%
	PostMessage, 0x105, %vk%, %sc%, , ahk_exe %proces%
}
User avatar
Xtra
Posts: 1370
Joined: 02 Oct 2015, 12:15

Re: PostMessage plz help

23 Apr 2017, 11:12

Your key parameter SystemKeyPress(key, proces) gets overwritten by your local variable key = ctrl

Basicly any value you pass to the key parameter gets set to ctrl.

HTH
User avatar
jeeswg
Posts: 6546
Joined: 19 Dec 2016, 01:58
Location: UK

Re: PostMessage plz help  Topic is solved

23 Apr 2017, 11:24

If you still have problems, this post (and the thread generally,) might help.

AutoHotkey source code: Send/ControlSend (modifier keys) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 98#p128898

I suppose what you're trying to do is 'SendInput' to a specific window. I had problems trying to send keys with modifier keys to a window via PostMessage, and ended up using dll calls involving threads.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
masheen
Posts: 294
Joined: 06 Dec 2016, 14:10

Re: PostMessage plz help

23 Apr 2017, 15:28

jeeswg wrote:If you still have problems, this post (and the thread generally,) might help.

AutoHotkey source code: Send/ControlSend (modifier keys) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 98#p128898

I suppose what you're trying to do is 'SendInput' to a specific window. I had problems trying to send keys with modifier keys to a window via PostMessage, and ended up using dll calls involving threads.
Thx u very much! its work great. Can i ask? how u get this?

Image

do u tell this method can PosetSend string?
string := "Hello World"
SendMessage, %????%, %????%, %string%, , ahk_id %hWnd%

i use for poststring this.

Code: Select all

PostString(string, process_title) {
	count_letter :=StrLen(string)
	loop %count_letter% {
		letter := SubStr(string, A_Index, 1)
		vk := GetKeyVK(letter), sc := GetKeySC(letter)
		PostMessage, 256, %vk%, %sc%, , %process_title%
	}
	return
}
User avatar
jeeswg
Posts: 6546
Joined: 19 Dec 2016, 01:58
Location: UK

Re: PostMessage plz help

23 Apr 2017, 16:05

To get the lParam value for SendMessage, you can use SendInput with one script, and OnMessage with another script.

To send text to a window I use:

Code: Select all

JEE_SendChars(vText, hWnd="")
{
	if (hWnd = "")
	{
		WinGet, hWnd, ID, A
		ControlGetFocus, vCtlClassNN, % "ahk_id " hWnd
		if !(vCtlClassNN = "")
			ControlGet, hWnd, Hwnd,, % vCtlClassNN, % "ahk_id " hWnd
	}
	Loop, Parse, vText
		PostMessage, 0x102, % Ord(A_LoopField), 1,, % "ahk_id " hWnd ;WM_CHAR
	return
}
Btw with Notepad for example, I had to send messages to the Edit control, sending messages to the Notepad window didn't work.

I haven't done too many experiments with sending keys to windows/controls yet, it was something I planned to do in future rewrites of my scripts.
Last edited by jeeswg on 10 May 2017, 10:30, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
masheen
Posts: 294
Joined: 06 Dec 2016, 14:10

Re: PostMessage plz help

23 Apr 2017, 16:15

jeeswg wrote:To get the lParam value for SendMessage, you can use SendInput with one script, and OnMessage with another script..
Can give me example plz?
User avatar
masheen
Posts: 294
Joined: 06 Dec 2016, 14:10

Re: PostMessage plz help

23 Apr 2017, 16:19

jeeswg wrote: Btw with Notepad for example, I had to send messages to the Edit control, sending messages to the Notepad window didn't work.
I haven't done too many experiments with sending keys to windows/controls yet, it was something I planned to do in future rewrites of my scripts.
This code will send not control/ This will send in Edit1 check it

Code: Select all


JEE_SendChars(vText, hWnd="")
{
	if (hWnd = "")
	{
		WinGet, hWnd, ID, A
		ControlGetFocus, vCtlClassNN, % "ahk_id " hWnd
		if !(vCtlClassNN = "")
			ControlGet, hWnd, Hwnd, , % vCtlClassNN, % "ahk_id " hWnd
	}
	Loop, Parse, vText
		PostMessage, 0x102, % Ord(A_LoopField), 1, Edit1, % "ahk_id " hWnd ; it will work to the Edit control
	return
}
PostMessage, 0x102, % Ord(A_LoopField), 1, Edit1, % "ahk_id " hWnd ;WM_CHAR

Image

jeeswg wrote:To get the lParam value for SendMessage, you can use SendInput with one script, and OnMessage with another script..
Can give me example plz?
User avatar
jeeswg
Posts: 6546
Joined: 19 Dec 2016, 01:58
Location: UK

Re: PostMessage plz help

23 Apr 2017, 16:34

I would use my function like this:

Code: Select all

JEE_SendChars("hello world")
or in the case of Notepad:

Code: Select all

ControlGet, hCtl, Hwnd,, Edit1, ahk_class Notepad
JEE_SendChars("hello world", hCtl)
When you use:
% "ahk_id " hWnd
hWnd can be a control or a window.

Btw, yes, the code where you modified my SendChars function, would work if the hWnd specified was that of Notepad's window.

==================================================

Example of SendInput and OnMessage scripts:

Code: Select all

;==================================================

;SCRIPT 1

q::
SendInput ^+{Left}
return

;==================================================

;SCRIPT 2

OnMessage(0x100, "KeyPress")
OnMessage(0x101, "KeyPress")

Gui, Add, Edit
Gui, Show
return

KeyPress(wParam, lParam, uMsg, hWnd)
{
	uMsg := Format("0x{:X}", uMsg)
	wParam := Format("0x{:X}", wParam)
	lParam := Format("0x{:08X}", lParam)
	Clipboard .= "`r`n" uMsg ", " wParam ", " lParam
}

;==================================================
[EDIT:] Best of luck. My original script in the link, worked for sending ctrl+shift+left and ctrl+left, but I've not been able to get ctrl+c and ctrl+v to work.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
masheen
Posts: 294
Joined: 06 Dec 2016, 14:10

Re: PostMessage plz help

23 Apr 2017, 17:12

[quote="jeeswg"][/quote]
Thx. u help me

Return to “Ask For Help”

Who is online

Users browsing this forum: coder_chick, flyingDman, Google [Bot], Groot, mkanet, return and 224 guests