mlaily/NegativeScreen

lost on the way to adding two keys

EternalTranquility1 opened this issue · 4 comments

hello total noob i really like the program, but i'm not sure how to add these two keys to invert or revert
Enable=win+alt+I
Disable=win+alt+R
because they don't work in negativescreen.conf and crashes the program, and i did more research, and chat gpt suggested adding the buttons with an ahk script? i'm so confused i just want to add two buttons to the program, and it's this difficult?

Hello, the functionality you are looking for (disable color effects or enable them with a dedicated hotkey) does not exist.

The only shortcuts close to what you want are a shortcut to toggle color effects, and one to exit the app.

I'm curious: why do you want to control enabling and disabling color effects independently?

@mlaily I was trying to make the program only invert the screen when specific applications are active, such as notepad and taskmanager, and only invert the screen when these two are active. I already had an ahk script, so all I needed were the enable and disable keys. Using the toggle is not an option because it will result in a random result.

This is the ahk script.

#Persistent
ProgramsToMonitor := ["notepad.exe", "taskmgr.exe"]
SetTimer, CheckActiveWindow, 50
Return

CheckActiveWindow:
WinGet, ProcessName, ProcessName, A
If (ProgramsToMonitor.Contains(ProcessName)) {
    If (ProcessExist("NegativeScreen.exe")) {
        Send !#i
    }
    else {
        RunWait, "D:\My Programs\NegativeScreen\NegativeScreen.exe"
        WinWait, ahk_exe NegativeScreen.exe
        Send !#i
    }
}
else {
    Send !#r
}
Return

ProcessExist(name)
{
    Process, Exist, %name%
    return ErrorLevel
}

Contains(haystack, needle) {
    return InStr(haystack, needle) > 0
}

All commands must be sent with the POST http method. The following commands are implemented:

TOGGLE
ENABLE
DISABLE
SET "Color effect name" (without the quotes)
Any request sent with a method other than POST will not be interpreted, and a response containing the application version will be sent.

Reading this, I assumed that I could simply add ENABLE and DISABLE to negativescreen.conf alongside TOGGLE and SET "Color effect name" and it would work, but since you say that doesn't exist, what do ENABLE and DISABLE do?

Ok I see.

The quote from the documentation mentioning ENABLE/DISABLE is about the internal http API.
These are not hot keys you can bind, but http commands you can call from outside.

This api is indeed meant to do the kind of thing you want possible.

The api is disabled by default though. You have to enable it by setting EnableApi to true in the config.
Once this is done, and if you keep the default listening url (ApiListeningUri=http://localhost:8990/ in the config), you can send http POST requests with one of the documented commands in the body of the request.

I don't know autohotkey well enough, but here is a working example with a powershell command:
Invoke-WebRequest http://localhost:8990/ -Method POST -Body TOGGLE (you can replace TOGGLE with ENABLE, DISABLE or SET xxx)

I didn't test it, but it looks like this could work with ahk:

whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("POST", "http://localhost:8990/")
body = "TOGGLE"
whr.Send(body)

@mlaily the PowerShell command did it for me, thank you! ♥