AutoHotkey recording Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ejdewan
Posts: 21
Joined: 12 Feb 2017, 16:42

AutoHotkey recording

12 Feb 2017, 17:00

As a first time user, I have a simple question, the answer to which I have been unable to find in the documentation. As a beginning project, I want to be able to toggle the View parameter "Show desktop icons" by using a single key press and release (the right Logo key). This requires that I right-click on the desktop background (not on an icon) and select View/Show..." In order to do this, I need to record the action, in the manner of typical word-processor macros. At first glance, I thought there was a record capability in AutoHotkey, but I can't find it. Also, if there is such a capability, will I be able to encode the requirement that I right-click on ANY location in the background that is not already occupied by an icon or something else? If not, I may have to resort to messing with the registry. Any help with this will be appreciated.
Guest

Re: AutoHotkey recording

12 Feb 2017, 17:04

A recorder can be found here https://autohotkey.com/boards/viewtopic.php?f=6&t=143 - if it will suit your needs I don't know.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: AutoHotkey recording  Topic is solved

12 Feb 2017, 17:50

Code: Select all

q:: ;show desktop icons (toggle) (tested on windows 7)
PostMessage, 0x111, 29698, , SHELLDLL_DefView1, ahk_class Progman ;show desktop icons (toggle)
Return

w:: ;show desktop icons (tested on windows 7)
ControlGet, vCtlStyle, Style, , SysListView321, ahk_class Progman
if !(vCtlStyle & 0x10000000) ;WS_VISIBLE := 0x10000000
PostMessage, 0x111, 29698, , SHELLDLL_DefView1, ahk_class Progman ;show desktop icons (toggle)
Return

e:: ;hide desktop icons (tested on windows 7)
ControlGet, vCtlStyle, Style, , SysListView321, ahk_class Progman
if (vCtlStyle & 0x10000000) ;WS_VISIBLE := 0x10000000
PostMessage, 0x111, 29698, , SHELLDLL_DefView1, ahk_class Progman ;show desktop icons (toggle)
Return
The wParam value 29698 is from:
Show/hide desktop icons in Windows 7 - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/4352 ... windows-7/
(Although they didn't find a clean solution to this problem.)

Menu item IDs can be found using:
Get Info from Context Menu - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/1975 ... text-menu/
The 'Show desktop icons' menu item ID was 30988, but this didn't work as the wParam value.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: AutoHotkey recording

12 Feb 2017, 18:07

Something different that also works

Code: Select all

#singleinstance force

Esc::
ExitApp

F1::
	ShowDesktopIcons(True)
Return

F2::
	ShowDesktopIcons(False)
Return

ShowDesktopIcons(bShow := True) {
	if(bShow) {
		bShow := 5
	}
	else {
		bShow := 0
	}
	WinGet, theDesktop, ID, ahk_class Progman
	theDesktopChilds := DllCall("GetWindow", "Ptr", theDesktop, "Uint", 5)  ; GW_CHILD = 5
	DllCall("ShowWindow", "Ptr", theDesktopChilds, "Uint", bShow)			; SW_HIDE = 0, SW_SHOW = 5
}
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: AutoHotkey recording

12 Feb 2017, 18:33

That method, retrieving the first child,
and showing/hiding it, is probably the same as:

Code: Select all

ControlGet, hCtl, Hwnd, , SysListView321, ahk_class Progman
WinHide, ahk_id %hCtl%

Sleep 2000

ControlGet, hCtl, Hwnd, , SysListView321, ahk_class Progman
WinShow, ahk_id %hCtl%
Interesting though, as I'm collecting AHK source code/equivalent methods information!
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: AutoHotkey recording

12 Feb 2017, 21:26

jeeswg wrote:Interesting though, as I'm collecting AHK source code/equivalent methods information!
Nice, I like it better than your sendmessage method.
I just translated some vb code I had, I didn't knew the exact AHK equivalent, I'll keep that in my lib, ty.
ejdewan
Posts: 21
Joined: 12 Feb 2017, 16:42

Re: AutoHotkey recording

13 Feb 2017, 00:02

Thank you all; that will give me something to chew on! I want to mark this post as solved, but it's not clear to me how to do this. There is a check mark beside each post which means "Accept this answer", but I'm not sure exactly what that does, and there doesn't appear to be a way to accept them all with one click. I will go now and try out these ideas. Thanks again.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: AutoHotkey recording

13 Feb 2017, 10:16

@ejdewan
If you click the 'Accept this answer' button on a post,
then that post gets a little green box with a white tick.
(The button's name then becomes 'Set topic as unsolved',
if you click it again, that undoes it, the green box is removed.)
You can only choose one post to be the answer.

I have never used a macro record program with AutoHotkey,
although occasionally I have checked 'View, Key history and script info'.
For a method based on key presses/mouse clicks,
this appeared to work:

Code: Select all

q::
ControlClick, x0 y0, ahk_class Progman, , R
WinWait, ahk_class #32768
ControlSend, , vd, ahk_class #32768
Return
I don't think there would ever be an icon at (0, 0),
but then I don't know if it is somehow possible!

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

@4GForce
In general, menus work by sending WM_COMMAND := 0x111,
and a menu ID number to a window/control.
So my method is the cleanest I could think of.
If you simply make the listview control shown/hidden directly,
the tick by the 'Show desktop icon' menu item is not updated
(which admittedly isn't the end of the world).

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

spy.exe which comes in the zip with HotkeyP
showed the number (wParam) 29698 (but not 30988, the menu item's ID)
when I ticked/unticked 'View, Show desktop icons'.

HotkeyP:
Freeware programs including Precise Calculator
http://petr.lastovicka.sweb.cz/others.html

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

[EDIT:]
The different methods I've tested seem to work intermittently.
Possibly more likely to work if the desktop is *not* the active window.
This may or may not have something to do with Progman v. WorkerW classes.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
ejdewan
Posts: 21
Joined: 12 Feb 2017, 16:42

<Solved> AutoHotkey recording

16 Feb 2017, 16:16

q:: ;show desktop icons (toggle) (tested on windows 7)
PostMessage, 0x111, 29698, , SHELLDLL_DefView1, ahk_class Progman ;show desktop icons (toggle)
Return

From jeeswg works like a charm! Thanks for all the good suggestions.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], robinson and 155 guests