Change the activation from win+a to F9+w?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
june
Posts: 5
Joined: 23 Aug 2018, 04:25

Change the activation from win+a to F9+w?

15 Jan 2023, 09:02

Hello.
I have found working wallpaper changer script which activates with win+a but I want to change it to F9+w

The script is this one

Code: Select all

; Initial Preferences

#SingleInstance Force
#NoEnv 
SendMode Input 
SetWorkingDir %A_ScriptDir%

; Few global variables

IniFile = %A_ScriptDir%\wpchange.ini
TempWallpaper = %A_MyDocuments%\currentwallpaper.jpg

IniRead, WallPaperFolder, %IniFile%, Settings, WPFolder, NOT_SET ;  Read settings from IniFile

If WallPaperFolder = NOT_SET ; If there is no IniFile, or it's set for Reset
{
 FileSelectFolder, SetFolder, , 3 ; Show a folder for the wallpapers
 if SetFolder =
 {
  MsgBox, You didn't select a folder, the program will now close. ; We can't function without a folder, if the user didn't select one, exit.
  ExitApp
 }
 else
 {
  SetFolder := RegExReplace(SetFolder, "\\$")  ; Removes the trailing backslash, if present. 
  WallPaperFolder = %SetFolder%\ ; We need the trailing backslash for our purposes, but removing it first eliminates the possibility of dual slashes.
  IniWrite, %WallPaperFolder%, %IniFile%, Settings, WPFolder ; Now that we have all the settings, write them to IniFile so we don't need to ask them again at relaunch
  MsgBox Setting saved. To reset, choose the "Reset Folder" item from tray or delete file %IniFile%.`n`nYou can now change your wallpaper at will by pressing "Win+A". The program will select a random image from the folder you provided and set it as your wallpaper.
 }
} 

RefreshWPs()
{
 Global
 ArrayCount=0
 Loop, %WallPaperFolder%*.jpg ; check all jpg images in the WallpaperFolder
 {
 ArrayCount+=1
 Array%ArrayCount% := A_LoopFileName ; Make an array of all the available filenames
 }
}

ChangeWP() 
{
 global
 Random, filenum, 1, %ArrayCount%
 filecalled := Array%filenum% ;  select a random image to be set as the new paper
 TrayTip, Wallpaper Changer, Setting "%filecalled%" as your wallpaper,,1
 FileCopy, %WallPaperFolder%%filecalled%, %TempWallpaper%, 1 ; copy the file to a temp location
 FileCopyError = %ErrorLevel%
 If ErrorLevel = 1
 {
  MsgBox While copying %WallPaperFolder%%filecalled% to a temporary location at %TempWallpaper%, a FileCopy error occured, please contact the developer!
 } 
 DllCall("SystemParametersInfo", UInt, 0x14, UInt, 0, Str, TempWallpaper, UInt, 2)
 RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, WallPaper, %WallPaperFolder%%filecalled%
 Sleep, 500 ; can't change the wallpaper too quickly in succession.
 return 
} 

Traytip, Wallpaper Changer, Refreshing Wallpapers...,,1
RefreshWPs()
TrayTip, Wallpaper Changer, Wallpaper list refreshed! (%ArrayCount% Found),,1
Menu, TRAY, Add
Menu, TRAY, Add, Refresh Wallpapers, RefreshWallpapers ; Manual refresh
Menu, TRAY, Add, Change Wallpaper, ChangeWallpaper ; Add a menu for it too
Menu, TRAY, Add
Menu, TRAY, Add, Reset Folder, RstFolder ; Add menu for resetting folder
Return ; Ends the auto-execute section

RefreshWallpapers: ; does the same job as the auto-execute
   Traytip, Wallpaper Changer, Refreshing Wallpapers...,,1
   RefreshWPs()
   TrayTip, Wallpaper Changer, Wallpaper list refreshed! (%ArrayCount% Found),,1
   Return

ChangeWallpaper:
 ChangeWP()
 Return

RstFolder:
 MsgBox, 52, Wallpaper Changer, Resetting folder settings requires program restart. You can choose new folder on next launch. Do you want to reset the settings and close the application now?
 IfMsgBox Yes
 {
  IniWrite, NOT_SET, %IniFile%, Settings, WPFolder ; Set the WPFolder as "NOT_SET" so next launch the user can choose a new folder.
  ExitApp
 }
 Else
 {
  TrayTip, Wallpaper Changer, Reset cancelled. Nothing done!,,1 ; Inform the user that we did nothing when "No" was clicked.
 } 
 Return

#a::ChangeWP()


==================================================
/ btw I think it`s the last one from here https://www.autohotkey.com/board/topic/43918-randomly-change-your-wallpaper-on-cue/ but looks like some things have been cut off./
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Change the activation from win+a to F9+w?

15 Jan 2023, 09:23

Code: Select all

#Requires AutoHotkey v1.1.33

; ................

F9::F9
F9 & w::ChangeWP()
User avatar
june
Posts: 5
Joined: 23 Aug 2018, 04:25

Re: Change the activation from win+a to F9+w?

15 Jan 2023, 11:04

Interesting. It works.
But what I was planning was to use the combo as a macro in my mouse software (mionix naos qg) which can`t accept the win button for some reason.
So now with f9 it was able to save it and run it but the result is invoking windows start menu? :wtf:
If I use the keyboard the command is working as expected. Any ideas what may be the problem?
User avatar
june
Posts: 5
Joined: 23 Aug 2018, 04:25

Re: Change the activation from win+a to F9+w?

17 Jan 2023, 17:38

I found the problem. I had to update my mouse software to the latest version. Now it works fine even with the default win+a.

Thanks for the help though! :thumbup:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: JKJadan, just me and 270 guests