dangustaargus Posted November 25, 2015 Share Posted November 25, 2015 I'm having trouble restricting the use of a particular key when an application is opened. I need to disable the f key (plus the f key during shift, ctrl, alt) when only one application is open. After that application is has been closed, I need the key to return to normal.If tried code related to Hotkeyset, and isPressed... but I'm not getting anything that works properly, and could use some help with syntax.Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 26, 2015 Moderators Share Posted November 26, 2015 dangustaargus,Just out of curiosity, why do you need to disable this specific key?M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Radiance Posted November 26, 2015 Share Posted November 26, 2015 (edited) I'd say HotKeySet would be a good start.Do one for each key and modifier you want to disable:HotKeySet("f", "_Function") ; f HotKeySet("!f", "_Function") ; alt + f HotKeySet("^f", "_Function") ; ctrl + f HotKeySet("+f", "_Function") ; shift + fThe function you'd call would basically be empty:Func _Function() Return EndFuncAfter that you make a loop and check if the application is still open.Depending on the app you could use ProcessExists(), WinExists(), WinActive(), etc.If the app is no longer running use the HotKeySet from above again while leaving the function name blanc.This will disable the HotKeySet.HotKeySet("f", "") Edited November 26, 2015 by Radiance Link to comment Share on other sites More sharing options...
kyo Posted November 26, 2015 Share Posted November 26, 2015 dangustaargus,Just out of curiosity, why do you need to disable this specific key?M23I've done something similar to this in the past, with legacy software that was in german, used by french-speaking people. I substituted the F1 key to provide useful help instead of having the original german help file popup. It's still in use today, hopefully not after Dec. 31st... Link to comment Share on other sites More sharing options...
dangustaargus Posted November 26, 2015 Author Share Posted November 26, 2015 dangustaargus,Just out of curiosity, why do you need to disable this specific key?M23I'm developing a menu application that launches a series of 11 other exe's (not my code - so I can't change key functionality). There are conflicts with the F key depending on the specific application. 2 in particular use the F key to exit fullscreen, which, if functional, breaks the user restrictions on the Kiosk.I need the F key to be shut off while these two applications are running, but functional if one of the other 9 is selected, because if that key is disabled, it breaks intended user functionality. The code I have now, using HotKeySet works as I'd like it to, but only if you press the F key for typing. Holding it down doesn't seem to work as intended... it kind of registers presses, and then immediately kills them as if they are false again. Resulting in stuttery, kind of fizzled out key responses; a keypress that apears to be true if immediately depressed, but not if held down.I'm building a set of museum kiosks, and this key needs to work some times, and not others, basically. With both key press and key held functionality. I'll give the above poster's method a shot when I can, but it appears very similar to what I already have. Link to comment Share on other sites More sharing options...
dangustaargus Posted November 26, 2015 Author Share Posted November 26, 2015 I'd say HotKeySet would be a good start.Do one for each key and modifier you want to disable:HotKeySet("f", "_Function") ; f HotKeySet("!f", "_Function") ; alt + f HotKeySet("^f", "_Function") ; ctrl + f HotKeySet("+f", "_Function") ; shift + fThe function you'd call would basically be empty:Func _Function() Return EndFuncAfter that you make a loop and check if the application is still open.Depending on the app you could use ProcessExists(), WinExists(), WinActive(), etc.If the app is no longer running use the HotKeySet from above again while leaving the function name blanc.This will disable the HotKeySet.HotKeySet("f", "") Thanks, I'm kind of already doing something like this, and it almost works. But only if I'm using the F key once as a quick press. If I hold it down, it only works for what appears to be a millisecond or so... and I need it to register as true for as long as the user holds the button down.I'll give this a shot though, as soon as I have the time. Link to comment Share on other sites More sharing options...
dangustaargus Posted November 26, 2015 Author Share Posted November 26, 2015 (edited) Thanks, I'm kind of already doing something like this, and it almost works. But only if I'm using the F key once as a quick press. If I hold it down, it only works for what appears to be a millisecond or so... and I need it to register as true for as long as the user holds the button down.I'll give this a shot though, as soon as I have the time.So I gave this a try but maybe I'm not understanding the syntax correctly because the F key seems to shut off no matter what conditionals I use, the moment I run the script. Here's how I understand it:Set the hotkeysets out of loopFunc _Function() if(ProcessExists("myApp.exe")) Then Return Else HotKeySet("f","") EndIf EndFunc While 1 othercode WEnd Sorry if this seems obvious but I'm mostly experienced with Java and some of the minutia of the logic and syntax is a little lost on me as I am still just learning to write these scripts. I guess if it'd be possible to more explicitly express the order of syntax for me that would be really helpful.Thanks. Edited November 26, 2015 by Jos Link to comment Share on other sites More sharing options...
Developers Jos Posted November 26, 2015 Developers Share Posted November 26, 2015 (edited) When is the Func being called to do something?Josps: put your code in a codebox Edited November 26, 2015 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
dangustaargus Posted November 28, 2015 Author Share Posted November 28, 2015 When is the Func being called to do something?Josps: put your code in a codeboxWhile 1 If(WinActive("SDL_app")) Then HotKeySet("f","kill_F") HotKeySet("+f","kill_F") HotKeySet("!f","kill_F") HotKeySet("^f","kill_F") HotKeySet("!+f","kill_F") Func kill_F() Return EndFunc Else HotKeySet("f","") EndIf ;other code down here Sleep(1000) WEnd This seems like it should work but it doesn't. If I run the script before I run the app, I have a functional F key. If I then run the offending app while the script is running... no F key, just as I'd hoped(and all the modifiers are killed too!). But then if I close the app and launch the one that requires the F key, the F key still stays dead. It is not restoring to full functionality after if SDL_app is no longer an active window. How is this logic incorrect? What am I missing here? Do I not understand if/else statements correctly? Link to comment Share on other sites More sharing options...
Developers Jos Posted November 28, 2015 Developers Share Posted November 28, 2015 Sounds like you have a program open that checks for keys as well and I get a lot of game related hits on SDL_app, so please ensure you understand out forumrules.Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
dangustaargus Posted November 28, 2015 Author Share Posted November 28, 2015 Sounds like you have a program open that checks for keys as well and I get a lot of game related hits on SDL_app, so please ensure you understand out forumrules.JosI have read the rules and I have actually explained this in a previous question I had. I'm working for a museum to develop a series of kiosk machines that launch the collected works of an artist (that happens to make games - Jason Rohrer, to be precise) for an exhibition in January. These are all open source works and the environment I'm developing is simply to ease access for users of the museum so that they can't leave the applications and roam the desktop (which I've already heavily restricted in that event anyway). That's the extent of these questions and this is the last hurdle in my work. I'd appreciate the help. This is the best program I've come across that will achieve a handful of my goals... I'm just more familiar with Java.To get back to the issue at hand, I'm also using the program SharpKeys to permanently disable a handful of keys... but that is a permanent registry hack that doesn't actually run in the background... My code also contains a HotKeySet outside of loop that tells the ESC key to kill every application on my list, but I'm not sure how that would conflict with F? But if I understand you correctly, this syntax is correct and there's nothing obviously wrong with this code? Link to comment Share on other sites More sharing options...
Developers Jos Posted November 28, 2015 Developers Share Posted November 28, 2015 I probably would have done it this way to avoid setting the keys every time and not to have an in-line Func:Global $keysset = 0 While 1 If WinActive("SDL_app") And $keysset = 0 Then HotKeySet("f", "kill_F") HotKeySet("+f", "kill_F") HotKeySet("!f", "kill_F") HotKeySet("^f", "kill_F") HotKeySet("!+f", "kill_F") $keysset = 1 Else HotKeySet("f", "") $keysset = 0 EndIf ;other code down here Sleep(1000) WEnd Func kill_F() Return EndFunc ;==>kill_FSo if this works with Notepad that the script is correct. When it doesn't with the other program then it is likely that other program blocking the key messages to reach the AutoIt3 script. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
dangustaargus Posted November 28, 2015 Author Share Posted November 28, 2015 I probably would have done it this way to avoid setting the keys every time and not to have an in-line Func:Global $keysset = 0 While 1 If WinActive("SDL_app") And $keysset = 0 Then HotKeySet("f", "kill_F") HotKeySet("+f", "kill_F") HotKeySet("!f", "kill_F") HotKeySet("^f", "kill_F") HotKeySet("!+f", "kill_F") $keysset = 1 Else HotKeySet("f", "") $keysset = 0 EndIf ;other code down here Sleep(1000) WEnd Func kill_F() Return EndFunc ;==>kill_FSo if this works with Notepad that the script is correct. When it doesn't with the other program then it is likely that other program blocking the key messages to reach the AutoIt3 script.So I just tried this on 3 separate computers (one with XP, one with 7, and one with 10) with notepad and in all instances I get the same behavior:F key works before script is runAfter script is launched, F key still worksAfter notepad is launched, F key does not workAfter notepad is closed, F key still does not work until script is killed Did you get this to work yourself? Link to comment Share on other sites More sharing options...
Developers Jos Posted November 28, 2015 Developers Share Posted November 28, 2015 Please show the script you tried with notepad.Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
dangustaargus Posted November 28, 2015 Author Share Posted November 28, 2015 Please show the script you tried with notepad.JosI used your code verbatim. Link to comment Share on other sites More sharing options...
dangustaargus Posted November 28, 2015 Author Share Posted November 28, 2015 Please show the script you tried with notepad.JosYou know what, here's the whole script just for the hell of it:expandcollapse popup#include <Timers.au3> HotKeySet("{ESC}","Terminate") Global $keysset = 0 ; close the list of running apps with esc key (because not all apps use ESC, and users love consistant) Func Terminate() if(ProcessExists("Transcend.exe") Or ("Cultivation.exe") Or ("Passage.exe") Or ("Gravitation.exe") Or ("StarFilledSky.exe") Or ("Idealism.exe") Or("Immortality.exe") Or ("PoliceBrutality.exe") Or ("i45hg.exe") Or ("Perfectionism.exe") Or ("Regret.exe")) Then ProcessClose("Transcend.exe") ProcessClose("Cultivation.exe") ProcessClose("Passage.exe") ProcessClose("Gravitation.exe") ProcessClose("StarFilledSky.exe") ProcessClose("Idealism.exe") ProcessClose("Immortality.exe") ProcessClose("PoliceBrutality.exe") ProcessClose("i45hg.exe") ProcessClose("Perfectionism.exe") ProcessClose("Regret.exe"); EndIf EndFunc ;Kill F while both SDL_app programs are running - restore after (currently broken) While 1 If WinActive("SDL_app") And $keysset = 0 Then HotKeySet("f","kill_F") HotKeySet("+f","kill_F") HotKeySet("!f","kill_F") HotKeySet("^f","kill_F") HotKeySet("!+f","kill_F") $keysset = 1 Else HotKeySet("f","") $keysset = 0 EndIf ;check if these two are active, if so force to front (user has too much time to click off window before fullscreen) If (ProcessExists("Transcend.exe") Or ("Cultivation.exe")) Then WinActivate("Transcend") WinActivate("Cultivation") EndIf ;kill list of apps after 5 minutes idle time if(ProcessExists("Transcend.exe") Or ("Cultivation.exe") Or ("Passage.exe") Or ("Gravitation.exe") Or ("StarFilledSky.exe") Or ("Idealism.exe") Or("Immortality.exe") Or ("PoliceBrutality.exe") Or ("i45hg.exe") Or ("Perfectionism.exe") Or ("Regret.exe")) And _Timer_GetIdleTime() > 300000 Then ;5 minutes ProcessClose("Transcend.exe") ProcessClose("Cultivation.exe") ProcessClose("Passage.exe") ProcessClose("Gravitation.exe") ProcessClose("StarFilledSky.exe") ProcessClose("Idealism.exe") ProcessClose("Immortality.exe") ProcessClose("PoliceBrutality.exe") ProcessClose("i45hg.exe") ProcessClose("Perfectionism.exe") ProcessClose("Regret.exe"); EndIf Sleep(1000); WEnd Func kill_F() Return EndFunc Link to comment Share on other sites More sharing options...
Developers Jos Posted November 28, 2015 Developers Share Posted November 28, 2015 That doesn't help much as I can't test with it, were I can test with the notepad version, hence the question to post that so I can test.Anyway, did a quick test with the the script I posted earlier and there was indeed some error and logic mistake.This versions works for me:Global $keysset = 0 While 1 If WinActive("Untitled - Notepad") Then If $keysset = 0 Then HotKeySet("f", "kill_F") HotKeySet("+f", "kill_F") HotKeySet("!f", "kill_F") HotKeySet("^f", "kill_F") HotKeySet("!+f", "kill_F") $keysset = 1 EndIf ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $keysset = ' & $keysset & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Else HotKeySet("f") $keysset = 0 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $keysset = ' & $keysset & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console EndIf ;other code down here Sleep(500) WEnd Func kill_F() Return EndFunc ;==>kill_FJos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
dangustaargus Posted November 28, 2015 Author Share Posted November 28, 2015 OMG this did it! I've been stuck on this for almost a week! Thank you!One thing: I copied your now functional code word for word and when I ran it the first time, I still had the same issue (wanted to scream!). But I noticed that I forgot to change the HotKeySet() in the Else from HotKeySet("f","") to HotKeySet("f"). I did fixed it, and it worked perfectly! It seems this might have actually been the culprit all along.Thank you so much! How do I send you a beer? Link to comment Share on other sites More sharing options...
Developers Jos Posted November 28, 2015 Developers Share Posted November 28, 2015 I'll stop by the next time I am in the neighborhood of Boston. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
dangustaargus Posted November 28, 2015 Author Share Posted November 28, 2015 I'll stop by the next time I am in the neighborhood of Boston. Jos Nice detective work. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now