Changing screen refresh rate with a keyboard shortcut

I have a little movie and tv-show collection and use the popular open-source mediacenter software Kodi to organize it. But as some tv-shows/movies have other image frequencies/fps than others, it necessary to change the screen refresh rate accordingly. Kodi already delivers an integrated functionality to automatically change the refresh rate as required.

Personally, I like to have some control over this, so I decided to develope a small windows application in C++ (with some C in order to work with the Win32 API) to accomplish this. Doing so a is definitely not a big task.

Initial requirements

As we make use of the windows API, we need to include the windows header files.

Taking a quick look at the documentations of a few functions we’ll use, shows that we need to include the library user32 into the compiler arguments. When using MinGW, the call will look something like this.

As the examples will contain some C++11 syntax, I also added the  proper parameter to compile these sources.

Changing the refresh rate

In order to change the refresh rate, you’ll first have to retrieve the available displays. You can do this by using the EnumDisplayDevices function. The displayId represents the index of the display. These indexes start with 0.

Next thing we need are the current display settings as we do not want to change anything but the display frequency. To accomplish this, we need to use EnumDisplaySettings function. As we’d like to query a specific display, we provide the DeviceName of the retrieved display.

Now having the currently active settings, we can simply change the property dmDisplayFrequency and call ChangeDisplaySettings with the updated struct.

Registering the keyboard shortcut

To register a keyboard shortcut, we need the RegisterHotKey function.

After registering the shortcut, we need to process particular events. To do this, we now create an event loop within our application. The struct variable wParam will hold the shortcut id. In this example, we won’t use it to actually distinguish between the different shortcuts but to directly provide the desired display frequency.

As the MinGW version I was using was missing the MOD_NOREPEAT definition, it had to be added manually.

Launching application

Now, we’re still missing the main function to fire everything up.

Create an executable without console

Finally we have to build our little application. As we’d like to have the application silently sit in the background, we don’t want a console to be displayed. To achieve this, we have to pass the argument -mwindows to our compiler.

This argument also ensures that the required windows libraries will be linked.

Example Code

I have attached two example codes. One which simply summarizes the above setup.

The other one is the actual implementation I’m using for my mediacenter setup. It also features small on-screen notifications showing the refresh rate that has been switched to. Rather than switching the frequency through multiple shortcuts, it cycles through a configured list.

Refresh Rate Changer Screenshot
Screenshot showing how the notification looks like when changing the refresh rate.

References

One thought on “Changing screen refresh rate with a keyboard shortcut”

  1. Ensuring the security of your home is essential in today’s unpredictable times. Among the best ways to secure your assets and sense of security is by investing in a reliable safe. No matter whether you’re securing funds, crucial records, or precious heirlooms, a safe gives a secure vault solution.

    When it comes to picking the appropriate safe for your home, there are several factors to consider. Above all, assess your safety requirements. Establish what items you expect to keep in the safe and the degree of protection required for every item.

    Following that, consider the size and positioning of the safe. Opt for a safe that suits comfortably in your residence while providing sufficient storage for your valuables. Ensure that the safe can be mounted in a safe spot, such as anchored to the floor or wall.

    In addition, inspect the protective elements of the safe. Seek out features such as strong construction, reliable locking mechanisms, and fireproof materials. Consider committing in a safe with added protection features, such as for instance biometric thumbprint scanners or electronic keypads.

    Finally, keep in mind to factor in your budget when choosing a safe. Establish a realistic budget based on your security needs and shop around for choices that match within your monetary constraints.

    Ultimately, picking the right safe for your residence is vital for keeping your valuables protected. By evaluating your safety requirements, taking into account the capacity and placement of the safe, looking into safety measures, and setting a financial plan, you can secure optimal protection for your valuable possessions.

    Scottsdale safe installation service – https://mercurylock.com/about

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.