Stateford / Display-Lock

Locks cursor to specified window and/or converts windows to borderless fullscreen, and prevents the cursor from spilling into another monitor
https://stateford.github.io/Display-Lock/
GNU General Public License v3.0
86 stars 8 forks source link

Is there a way to have the cursor auto lock in a particular game without having to do anything? #112

Closed gaveitatry2 closed 1 year ago

gaveitatry2 commented 1 year ago

I have a game that I play regularly. I have a shortcut to it pinned to my taskbar. I use your program to lock the cursor inside the borders. To make that easier, I have the Display Lock program visible in the Windows 10 notification tray area. I then have to double click that program icon, open up Display Lock, and even though my game is usually selected... I have to re-select it, then press Start, and THEN the cursor is locked. But oftentimes, I completely forget to do these steps. And I'll end up opening up like six other games while playing the one I am in, which causes me to crash. It's a real headache.

So I was wondering if there is any way that I can bypass all that and just auto cursor lock the game whenever I play it. I have a macro program that I use. It automatically detects whenever I am inside the game window, and it does things for me like auto moves the window up to x=0 and y=-24 to hide the title bar. It would be cool if I could tell this macro to auto run a Display Lock script so that I don't have to do anything and once I'm in the game window the cursor is automatically locked. Or as someone requested years ago, maybe white list this game so whenever I am playing it the cursor is automatically locked. I'm just looking for ways to auto lock the cursor in this game without having to remember to open up Display Lock each and every time. Any ideas or code edits (add features) that can be done?

Stateford commented 1 year ago

It's possible to add this feature to the program. It's been a while since I've looked at display lock, but I'll take another look at adding this feature,

Stateford commented 1 year ago

I had a quick look and it's doable. I've already started, but it's going to be a bit of work. Remember this is in C using the win32 API.

Just to be clear here this is the functionality you would like:

I need to thing about the functionality a bit as there is a lot of work that needs to be added to support this.

What happens if you want to undo the settings while you already in the application.

gaveitatry2 commented 1 year ago

Yes, I am playing a very stubborn game called Sven Co-op. At first I just wanted to change the window size (which is 99% impossible when trying different things like DxWnd, Steam launch parameters, game config edits, etc.), and I finally figured out how to do that using a Special K dll. But then I got so aggravated about my mouse cursor always leaving the window and clicking on things. So I tried your program. But as I mentioned I always forget to double click on the system tray area icon for your program and select my game and press Start. Plus it is a lot of steps. So I tried to find other cursor lock programs and none of them worked as well as yours. I learned how to cursor lock in Special K, but for some stupid reason they made it so that the cursor is on the OUTER edges of the window borders, and you can accidentally click on the title bar and drag the window around or accidentally click on the minimize and close buttons. I mentioned this on their Discord and all the people who are really active on the server just kept saying things like "why not just use borderless window" or "it's good that people can click on the minimize button when gaming" or "why did you delete your chat history for three months ago?" and just a lot of BS.

Ideally, I'd just like to start the game and not have to do anything. The cursor will already be locked. I thought that this could be accomplished two ways. One is make Display Lock auto detect the game so when I start it and it is active and in the front, the cursor is already locked. I'm not sure how you'd do that. One way is to detect by .exe. Another way is to detect by window title. But window titles often change. I'm not sure if they change in this game. But if window titles change, then wildcard asterisks * might be necessary so I could use something like an asterisk before Sven Co-op and one after it and that way if there is anything before or after Sven Co-op in the window title, the game will still be detected. Selecting the game by it's .exe might be better and more reliable. The second method I was thinking of is in my program VoiceMacro, it auto detects that Sven Co-op is running based on svencoop.exe, and I tell VoiceMacro to do things while the game is in the front and active. And maybe you could have a Display Lock script (not program) that I can tell VoiceMacro to activate whenever the game window is in the front and active. So the script will make whichever window (that VoiceMacro runs the script for) cursor locked but when I leave that window and click on another window the cursor lock is disengaged.

As for "changing settings" while using Display Lock with a whitelisted exe, well I can try to make some thoughts with that. One is if the program settings (borderless, fullscreen) need to be combined with that particular whitelisted program, then that's fine because if that needs to be changed the person can just close the application and modify the whitelisted exe's settings until they get what they want. There is no reason to continuously update or change these settings again and again while playing the game. Those are settings that rarely need to be touched. Another thought is maybe settings per application don't need to be touched. Personally, I only have "Minimize on Start" and "Check updates on Startup" checked because I don't like Borderless Window or Full Screen. So for me, I'd just be happy to have the Display Lock program running hidden on notification tray area and it just to auto detect my svencoop.exe when it is active and in the front and to auto lock it. And if I need to make adjustments to the program settings for that exe application, I can just close the game, change it to Borderless Window or Fullscreen, relaunch the game with those new program settings, and the game already be auto locked because it is whitelisted (without application settings). Really, I think the only thing that needs to be done is white list an executable by it's exe (or if you make EITHER exe and window title make it so you can use wildcards for the window title). The game window title changes. Like it starts off "Sven Co-op" when I start the game, but later it changes to "Sven Co-op listen server - Sven Co-op" when I start a private game. Or if I join a game, it might change to something else.

Stateford commented 1 year ago

Yes, I am playing a very stubborn game called Sven Co-op.

HAH! I used to play this game back in the day. I think it might've been pre-steam even.

As for "changing settings" while using Display Lock with a whitelisted exe, well I can try to make some thoughts with that. One is if the program settings (borderless, fullscreen) need to be combined with that particular whitelisted program, then that's fine because if that needs to be changed the person can just close the application and modify the whitelisted exe's settings until they get what they want.

I agree with this. I'll get to work on implementing this, and I have an excuse to launch sven co-op again :)

Stateford commented 1 year ago

So I have the feature working now. I have also added settings to auto enable borderless window + fullscreen however I have the ability to select these options locked because there is an issue.

The problem is these options will break the game as it makes the changes to the windows style before it can fully load which breaks things. I'll tackle these at another time so I can get this feature out for you.

There's a few things left to do which include fixing CI/CD so I can build the project and make a proper release.

gaveitatry2 commented 1 year ago

Sounds awesome! When can I give it a try? I'd like to test it out before you make the official release.

Stateford commented 1 year ago

Once I get the CI/CD pipeline up and running on the develop branch. I'm not sure I'll be able to get to it until the weekend as I'm pretty busy the next few days.

I will ping you as soon as it's up

Stateford commented 1 year ago

https://github.com/Stateford/Display-Lock/releases/tag/2.1.7

check out this release. If you run into any issues please report it.

gaveitatry2 commented 1 year ago

Thanks. I know you've been super busy with this and been working all weekend on it. Thanks for all your hard work. I started up Display Lock and I clicked on the Applications tab and then I added the svencoop.exe to it. But as soon as I do that, the Display Lock window closes and then the Display Lock .exe closes.

gaveitatry2 commented 1 year ago

Update: I tried it three times and each time the window closed and the program shut down. But on the fourth try, it worked. So that's good!

gaveitatry2 commented 1 year ago

Update: When I exit Display Lock and then restart it, it does not auto minimize even though I have "Minimize on Start" selected.

Stateford commented 1 year ago

Looking into it now.

Stateford commented 1 year ago

Update: When I exit Display Lock and then restart it, it does not auto minimize even though I have "Minimize on Start" selected.

This options is confusing. It's referring to minimizing display lock when you lock. This isn't when Display Lock opens. This should be more clear and I'll open an issue to resolve this in the future.

Thanks. I know you've been super busy with this and been working all weekend on it. Thanks for all your hard work. I started up Display Lock and I clicked on the Applications tab and then I added the svencoop.exe to it. But as soon as I do that, the Display Lock window closes and then the Display Lock .exe closes.

hmmm, I haven't been able to reproduce this. Is it still doing that? It might have something to do with where APPDATA is located.

Can copy and paste this into your file browser and see if this directory exists? %APPDATA%/DisplayLock

There should be two files in there, settings.DLOCK and applications.DLOCK

Stateford commented 1 year ago

Ok, I have reproduced it, investigating a fix

Stateford commented 1 year ago

Fix is coming, I deleted some lines of code I had in before and it broke things. Whoops.

WARNING Technical details below:

There was a race condition caused from the UI thread updating the same memory location as the locking thread.

This will be resolved in 2.1.8, I'll ping you as soon as it's published

Stateford commented 1 year ago

@gaveitatry2 https://github.com/Stateford/Display-Lock/releases/tag/2.1.8

Download it here, should be fixed. Any other issues feel free to open another issue to keep track of them

gaveitatry2 commented 1 year ago

Thank you. It seems to be working now. It did not crash or close. Also, I was able to create a shortcut to the program. And in the shortcut Properties, I have it set to Run: Minimized, so now it is automatically minimized. Thank you so much for this. It's a HUGE improvement. I can finally enjoy my game. :)

Stateford commented 1 year ago

Absolutely, if you run into any other problems or have a suggestion feel free to create an issue :)

Stateford commented 1 year ago

@gaveitatry2 There was a problem with the initial deployment to 2.1.8. The change wasn't pushed properly to the version you downloaded.

https://github.com/Stateford/Display-Lock/releases/tag/2.1.8

I fixed it, you will have to re-download it. This was my mistake, sorry about the inconvenience!

gaveitatry2 commented 1 year ago

Oh, okay. I will download it now. Thank you for the heads up! Edit: I downloaded it and it seems to be working. Thanks!