Script work if lauched through VS Code but does not work when launched through normally. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kenji
Posts: 16
Joined: 08 Nov 2021, 03:15

Script work if lauched through VS Code but does not work when launched through normally.

Post by kenji » 05 Dec 2021, 14:32

this is library - [https://gist.github.com/qwerty12/4b3f41eb61724cd9e8f2bb5cc15c33c2][/qwerty12/BrightnessSetter.ahk]

this is the code -

Code: Select all

#SingleInstance, Force
SendMode Input
SetWorkingDir, %A_ScriptDir%
#include <BrightnessSetter>


PgUp::BrightnessSetter.SetBrightness(10)
PgDn::BrightnessSetter.SetBrightness(-10)
when i run the .ahk file through VS Code menu using vs code extension - AutoHotkey Plus Plus v2.8.1
this pageup and pagedown works .

but if i run the script by going though windows explorer or autostart. it just shows up the brightness menu but does not change it.

also i have save the library in "Lib" folder where the .ahk script is saved.

User avatar
mikeyww
Posts: 26879
Joined: 09 Sep 2014, 18:38

Re: Script work if lauched through VS Code but does not work when launched through normally.

Post by mikeyww » 05 Dec 2021, 14:40

This is not exactly an answer but another technique easily done.

Code: Select all

PgDn::ChangeBrightness(GetCurrentBrightness() - 10)
PgUp::ChangeBrightness(GetCurrentBrightness() + 10)

ChangeBrightness(ByRef brightness, timeout := 1) {
 brightness := Max(0, Min(brightness, 100))
 For property in ComObjGet("winmgmts:\\.\root\WMI").ExecQuery("SELECT * FROM WmiMonitorBrightnessMethods")
  property.WmiSetBrightness(timeout, brightness)
}

GetCurrentBrightness() {
 For property in ComObjGet("winmgmts:\\.\root\WMI").ExecQuery("SELECT * FROM WmiMonitorBrightness")
  Return property.CurrentBrightness
}

kenji
Posts: 16
Joined: 08 Nov 2021, 03:15

Re: Script work if lauched through VS Code but does not work when launched through normally.

Post by kenji » 05 Dec 2021, 14:49

mikeyww wrote:
05 Dec 2021, 14:40
yuup it works. Thanks for this scrip.
the thing is it does not show the slide UI..
but if i did not find the answer than i will use this version.

User avatar
mikeyww
Posts: 26879
Joined: 09 Sep 2014, 18:38

Re: Script work if lauched through VS Code but does not work when launched through normally.  Topic is solved

Post by mikeyww » 05 Dec 2021, 15:14

Here is an on-screen display in case that helps.

Code: Select all

Gui +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, Color, EEAA99
Gui, Font, s160 w700
Gui, Add, Text, w700 vttext cLime Center
WinSet, TransColor, EEAA99 150

PgDn::ChangeBrightness(GetCurrentBrightness() - 10)
PgUp::ChangeBrightness(GetCurrentBrightness() + 10)

ChangeBrightness(ByRef brightness, timeout := 1) {
 For property in ComObjGet("winmgmts:\\.\root\WMI").ExecQuery("SELECT * FROM WmiMonitorBrightnessMethods")
  property.WmiSetBrightness(timeout, brightness := Max(0, Min(brightness, 100)))
 GuiControl,, ttext, %brightness%
 Gui, Show, NoActivate
 SetTimer, Stop, -1200
 Return
 Stop:
 Gui, Hide
 Return
}

GetCurrentBrightness() {
 For property in ComObjGet("winmgmts:\\.\root\WMI").ExecQuery("SELECT * FROM WmiMonitorBrightness")
  Return property.CurrentBrightness
}


Post Reply

Return to “Ask for Help (v1)”