Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lost on the way to adding two keys #31

Open
EternalTranquility1 opened this issue May 9, 2023 · 4 comments
Open

lost on the way to adding two keys #31

EternalTranquility1 opened this issue May 9, 2023 · 4 comments

Comments

@EternalTranquility1
Copy link

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?

@mlaily
Copy link
Owner

mlaily commented May 9, 2023

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?

@EternalTranquility1
Copy link
Author

@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?

@mlaily
Copy link
Owner

mlaily commented May 10, 2023

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)

@EternalTranquility1
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants