Jump to content

Disable key with specific app and restore when that app is closed


Recommended Posts

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

  • Moderators

dangustaargus,

Just out of curiosity, why do you need to disable this specific key?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 + f

The function you'd call would basically be empty:

Func _Function()
    Return
EndFunc

After 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 by Radiance
Link to comment
Share on other sites

dangustaargus,

Just out of curiosity, why do you need to disable this specific key?

M23

I'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

dangustaargus,

Just out of curiosity, why do you need to disable this specific key?

M23

I'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

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 + f

The function you'd call would basically be empty:

Func _Function()
    Return
EndFunc

After 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

 

 

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 loop

Func _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 by Jos
Link to comment
Share on other sites

  • Developers

When is the Func being called to do something?

Jos

ps: put your code in a codebox

Edited 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

When is the Func being called to do something?

Jos

ps: put your code in a codebox

While 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

  • Developers

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

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

I 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

  • Developers

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_F

So 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

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_F

So 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 run

After script is launched, F key still works

After notepad is launched, F key does not work

After 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

Please show the script you tried with notepad.

Jos

You know what, here's the whole script just for the hell of it:

#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

  • Developers

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_F

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...