Wow Winlock.dll

BlitzPlus Forums/BlitzPlus Programming/Wow Winlock.dll

Grey Alien(Posted 2005) [#1]
OK, if you want to block all unwanted windows key combos in your app, especially if it's full-screen, do the following:

1) Go here http://www.vandog.com/loc.html and download the lock o'clock program and install it (it's totally freeware).

2) Then get the newly installed winlock.dll from the windows folder and put it in your blitz application folder (the author says you can do this for free, yipee). I'm not going to post a link to the .dll, as he might not like me "distributing" it.

3) Make a new file in BlitzPlus\userlibs called winlock.decls and add this to it
.lib "winlock.dll"
LockKeys():"LockKeys"
UnlockKeys():"UnlockKeys"

4) When your application loads, simply call LockKeys
5) When your application exits, call UnlockKeys
6) Thats it!

Some problems:
- I wouldn't recommend using it when developing because you can't alt+tab to anything else of course.
- If you close your app without calling UnlockKeys or it crashes, the next time you run it, for some reason the keys won't be locked. You have to validly (is there such a word) exit it and restart it before the keys are locked.
- On my game Alt+Esc is not locked and it seems to take me back to windows with the game minimised but I can't click on it to go back in and Ctrl+Alt+Del is disabled so I can't kill it!
- Pressing Ctrl+Alt+Del isn't actually disabled, task manager is, so your app will still go back to windows and you'll see a message saying "Task Manager has been disabled by your administrator", bummer.
- Once after fiddling with it I couldn't use Ctrl+Alt+Del or Windows R (for Run) or Click Start/Run (it wasn't there) even after a reboot. I had to rerun my app and exit it properly and then everything restored. This implies the Dll doesn't just trap keys, it also fiddles with the registry which is dangerous imho.
- A major problem is that if you run in windowed mode and hit minimise, you can't restore the window at all (as far as I can see). This isn't so good. I haven't a clue why!

This dll could be made better by someone with some knowledge to avoid the registry hacks. I know that for sure it uses User32.dll SetWindowsHookEx which calls a custom function that traps and cancels keys and then calls CallNextHookEx (to carry on processing). Then later the hook is disabled with UnhookWindowsHookEx. I could (maybe) write a blitz wrapper for this if only I knew how to pass a pointer to a custom function (made in blitz) into a dll call. Anyone know?

try it out, it's good and it's bad.