Jump to content

DisableInput key exceptions


Tasmania
 Share

Recommended Posts

For my script, I want to keep ESC enabled, however even though HotKeySet is ESC, when disable input is enabled, it doesn't allow ESC to be pressed. I searched for a way to allow exceptions to disable input, however I didn't find anything. I find it hard to believe that this hasn't been posted before, so in my different variations of searching to disable input except one button I still was unable to find it. Most likely this has to do with my wording, so I'm sorry ahead of time.

AutoItSetOption("TrayIconDebug", 1)
AutoItSetOption("SendKeyDelay", 1)

HotKeySet("{ESC}", "panic")
HotKeySet("!{F4}", "panic")
HotKeySet("^!s", "save")
HotKeySet("^!n", "new")
HotKeySet("^!o", "open")

Func panic()
 Exit
EndFunc

Func new()
 GUICtrlSetData($txtAttn, "")
 GUICtrlSetData($txtEmail, "")
 GUICtrlSetData($txtPwo, "")
 GUICtrlSetData($txtInum, "")
 GUICtrlSetData($txtSca, "")
 GUICtrlSetData($txtDesc, "")
 GUICtrlSetData($dteRstdate, "")
 GUICtrlSetData($cmbType, "CONCEPT")
 GUICtrlSetData($cmbPcode, "SAM-CONCPT")
 GUICtrlSetData($txtPO, "N/C")
 GUICtrlSetData($txtPOamt, "0")
 GUICtrlSetData($txtPOdiscount, "")
 GUICtrlSetData($txtPE, "")
 GUICtrlSetData($txtPM, "")
 GUICtrlSetData($txtCharge, "")
 GUICtrlSetData($txtQty, "1.00")
 GUICtrlSetData($txtMaterial, "")
 GUICtrlSetData($txtGauge, "0.0")
 GUICtrlSetData($edtExNotes, "")
 
 ControlFocus("Syte Line Automation", "", $txtAttn)
EndFunc

Func save()
 DirCreate(@MyDocumentsDir & "\Syte Line Automation\")
 
 $filesaveloc = FileSaveDialog("Save...", @MyDocumentsDir & "\Syte Line Automation\", "Syte Line Automation Files (*.sla)", 16, @MON & @MDAY & @YEAR & @HOUR & @MIN & @SEC & ".sla")
 
 If Not @error Then
  $file = FileOpen($filesaveloc, 10)
  
  If $file = -1 Then
   MsgBox(64, "Error", "Unable to open file.")
   Exit
  EndIf
  
  FileWriteLine($file, GUICtrlRead($txtAttn))
  FileWriteLine($file, GUICtrlRead($txtEmail))
  FileWriteLine($file, GUICtrlRead($txtPwo))
  FileWriteLine($file, GUICtrlRead($txtInum))
  FileWriteLine($file, GUICtrlRead($txtSca))
  FileWriteLine($file, GUICtrlRead($txtDesc))
  FileWriteLine($file, GUICtrlRead($dteRstdate))
  FileWriteLine($file, GUICtrlRead($cmbType))
  FileWriteLine($file, GUICtrlRead($cmbPcode))
  FileWriteLine($file, GUICtrlRead($txtPO))
  FileWriteLine($file, GUICtrlRead($txtPOamt))
  FileWriteLine($file, GUICtrlRead($txtPOdiscount))
  FileWriteLine($file, GUICtrlRead($txtPE))
  FileWriteLine($file, GUICtrlRead($txtPM))
  FileWriteLine($file, GUICtrlRead($txtCharge))
  FileWriteLine($file, GUICtrlRead($txtQty))
  FileWriteLine($file, GUICtrlRead($txtMaterial))
  FileWriteLine($file, GUICtrlRead($txtGauge))
  FileWrite($file, GUICtrlRead($edtExNotes))
  
  FileClose($file)
  
  MsgBox(64, "Save Complete", "File has been saved.")
 EndIf
EndFunc

Func open()
 $fileopenloc = FileOpenDialog("Open...", @MyDocumentsDir & "\Syte Line Automation\", "Syte Line Automation Files (*.sla)")
 
 If Not @error Then
  $edtcnts = ""
  $file = FileOpen($fileopenloc, 0)
  
  If $file = -1 Then
   MsgBox(64, "Error", "Unable to open file.")
   Exit
  EndIf
  
  GUICtrlSetData($txtAttn, FileReadLine($file))
  GUICtrlSetData($txtEmail, FileReadLine($file))
  GUICtrlSetData($txtPwo, FileReadLine($file))
  GUICtrlSetData($txtInum, FileReadLine($file))
  GUICtrlSetData($txtSca, FileReadLine($file))
  GUICtrlSetData($txtDesc, FileReadLine($file))
  
  $filedate = FileReadLine($file)
  $filedatearr = StringSplit($filedate, "/")
  $newdate = $filedatearr[3] & "/" & $filedatearr[1] & "/" & $filedatearr[2]
  
  GUICtrlSetData($dteRstdate, $newdate)
  GUICtrlSetData($cmbType, FileReadLine($file))
  GUICtrlSetData($cmbPcode, FileReadLine($file))
  GUICtrlSetData($txtPO, FileReadLine($file))
  GUICtrlSetData($txtPOamt, FileReadLine($file))
  GUICtrlSetData($txtPOdiscount, FileReadLine($file))
  GUICtrlSetData($txtPE, FileReadLine($file))
  GUICtrlSetData($txtPM, FileReadLine($file))
  GUICtrlSetData($txtCharge, FileReadLine($file))
  GUICtrlSetData($txtQty, FileReadLine($file))
  GUICtrlSetData($txtMaterial, FileReadLine($file))
  GUICtrlSetData($txtGauge, FileReadLine($file))
  While 1
   $edtcnts &= FileRead($file, 1)
   If @error = -1 Then ExitLoop
  WEnd
  GUICtrlSetData($edtExNotes, $edtcnts)
 EndIf
EndFunc

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\USPJEFE\Desktop\Projects\frmQuestions.kxf
$frmCInfo = GUICreate("Syte Line Automation", 420, 333, -1, -1)
$grpInfo = GUICtrlCreateGroup("Information", 0, 0, 417, 241)
$lblAttn = GUICtrlCreateLabel("Attn:", 8, 17, 32, 17)
$txtAttn = GUICtrlCreateInput("", 96, 17, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL))
$lblEmail = GUICtrlCreateLabel("Email:", 8, 41, 38, 17)
$txtEmail = GUICtrlCreateInput("", 96, 41, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL))
$lblPwo = GUICtrlCreateLabel("PWO #:", 8, 65, 49, 17)
$txtPwo = GUICtrlCreateInput("", 96, 65, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL))
$lblInum = GUICtrlCreateLabel("Full Item Num:", 8, 89, 77, 17)
$txtInum = GUICtrlCreateInput("", 96, 89, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL))
$lblSca = GUICtrlCreateLabel("SCA # (No 0):", 8, 113, 76, 17)
$txtSca = GUICtrlCreateInput("", 96, 113, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL))
$lblDesc = GUICtrlCreateLabel("Description:", 8, 137, 66, 17)
$txtDesc = GUICtrlCreateInput("", 96, 137, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL))
$lblRstdate = GUICtrlCreateLabel("Request Date:", 8, 161, 79, 17)
$dteRstdate = GUICtrlCreateDate("", 96, 161, 105, 21, $WS_TABSTOP)
$lblType = GUICtrlCreateLabel("Type:", 8, 184, 37, 17)
$cmbType = GUICtrlCreateCombo("CONCEPT", 96, 184, 105, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$CBS_UPPERCASE))
GUICtrlSetData(-1, "RECONCEPT|SAMPLE|RESAMPLE|ADDL SMPL|HEAT SEAL TOOL|BLISTR FRM TOOL")
$lblProdCode = GUICtrlCreateLabel("Product Code:", 8, 208, 78, 17)
$cmbPcode = GUICtrlCreateCombo("SAM-CONCPT", 96, 208, 105, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$CBS_UPPERCASE))
GUICtrlSetData(-1, "SAM-SAMPL|SAM-ADDL|MAH-FAC|MAH-FAM|BFT-VAC|BFT-PRESS")
$lblPO = GUICtrlCreateLabel("PO Number:", 216, 17, 68, 17)
$txtPO = GUICtrlCreateInput("N/C", 304, 17, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL))
$lblPOamt = GUICtrlCreateLabel("PO Amount:", 216, 41, 67, 17)
$txtPOamt = GUICtrlCreateInput("0", 304, 41, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL))
$lblPOdiscount = GUICtrlCreateLabel("PO Discount:", 216, 64, 73, 17)
$txtPOdiscount = GUICtrlCreateInput("", 304, 64, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL))
$lblPE = GUICtrlCreateLabel("Project Enj:", 216, 89, 64, 17)
$txtPE = GUICtrlCreateInput("", 304, 89, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL))
GUICtrlSetLimit(-1, 2)
$lblPM = GUICtrlCreateLabel("Project Mngr:", 216, 113, 73, 17)
$txtPM = GUICtrlCreateInput("", 304, 113, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL))
GUICtrlSetLimit(-1, 2)
$lblCharge = GUICtrlCreateLabel("Charge:", 216, 137, 47, 17)
$txtCharge = GUICtrlCreateInput("", 304, 137, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL))
$lblQty = GUICtrlCreateLabel("Quantity:", 216, 160, 52, 17)
$txtQty = GUICtrlCreateInput("1.00", 304, 160, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL))
$lblMaterial = GUICtrlCreateLabel("Material:", 216, 184, 50, 17)
$txtMaterial = GUICtrlCreateInput("", 304, 184, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL))
$lblGauge = GUICtrlCreateLabel("Gauge:", 216, 208, 45, 17)
$txtGauge = GUICtrlCreateInput("0.0", 304, 208, 105, 21, BitOR($ES_UPPERCASE,$ES_AUTOHSCROLL))
GUICtrlCreateGroup("", -99, -99, 1, 1)
$lblExNotes = GUICtrlCreateLabel("Extra Notes:", 8, 248, 68, 17)
$edtExNotes = GUICtrlCreateEdit("", 80, 248, 241, 57, BitOR($ES_UPPERCASE,$ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
GUICtrlSetData(-1, "")
$btnContinue = GUICtrlCreateButton("Continue", 336, 248, 75, 25)
$btnExit = GUICtrlCreateButton("Exit", 336, 280, 75, 25)
$mnuFile = GUICtrlCreateMenu("&File")
$mnuNew = GUICtrlCreateMenuItem("&New" & @TAB & "Ctrl-Alt-N", $mnuFile)
$mnuOpen = GUICtrlCreateMenuItem("&Open" & @TAB & "Ctrl-Alt-O", $mnuFile)
$mnuSave = GUICtrlCreateMenuItem("&Save" & @TAB & "Ctrl-Alt-S", $mnuFile)
$mnuSep1 = GUICtrlCreateMenuItem("", $mnuFile)
$mnuExit = GUICtrlCreateMenuItem("E&xit" & @TAB & "Alt-F4", $mnuFile)
$mnuEdit = GUICtrlCreateMenu("&Edit")
$mnuCopy = GUICtrlCreateMenuItem("&Copy" & @TAB & "Ctrl-C", $mnuEdit)
$mnuPaste = GUICtrlCreateMenuItem("&Paste" & @TAB & "Ctrl-V", $mnuEdit)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; ********** Variables that are needed to start **********
Global $displayed = 0
Global $readonly = 0
; ********** End variables that are needed to start **********

While 1
 $nMsg = GUIGetMsg()
 
 Switch $nMsg
  Case $GUI_EVENT_CLOSE
   panic()
   
  Case $btnExit
   panic()
   
  Case Not $txtInum
   If StringLen(GUICtrlRead($txtInum)) > 0 And $displayed <= 2 Then
    If StringInStr(GUICtrlRead($txtInum), "SAMPLE") Then
     GUICtrlSetData($cmbType, "SAMPLE")
     GUICtrlSetData($cmbPcode, "SAM-SAMPL")
     $displayed += 1
    ElseIf StringInStr(GUICtrlRead($txtInum), "ADDSAM") Then
     GUICtrlSetData($cmbType, "ADDL SAMPL")
     GUICtrlSetData($cmbPcode, "SAM-ADDL")
     $displayed += 1
    ElseIf StringInStr(GUICtrlRead($txtInum), "CONCEPT") Then
     GUICtrlSetData($cmbType, "CONCEPT")
     GUICtrlSetData($cmbPcode, "SAM-CONCPT")
     $displayed += 1
    ElseIf StringInStr(GUICtrlRead($txtInum), "H") Then
     GUICtrlSetData($cmbType, "HEAT SEAL TOOL")
     GUICtrlSetData($cmbPcode, "MAH-FAC")
     $displayed += 1
    ElseIf StringInStr(GUICtrlRead($txtInum), "FORMTOOL") Then
     GUICtrlSetData($cmbType, "BLISTER FORM TOOL")
     GUICtrlSetData($cmbPcode, "BFT-VAC")
     $displayed += 1
    EndIf
   ElseIf StringLen(GUICtrlRead($txtInum)) = 0 And $displayed <= 3 Then
    $displayed = 0
   EndIf
   
  Case $mnuExit
   panic()
   
  Case $mnuNew
   new()
   
  Case $mnuSave   
   save()
   
  Case $mnuOpen
   open()
   
  Case $mnuCopy
   Send("^c")
   
  Case $mnuPaste
   Send("^v")
   
  Case $btnContinue
   GUISetState(@SW_HIDE)
   
   ;BlockInput(1)
   
   #include <test-include.au3>
   
   clear_all()
   
   ;BlockInput(0)
   
   GUISetState(@SW_SHOW)
 EndSwitch
WEnd
Link to comment
Share on other sites

You post way too much code for such a little script question. Just enable/disable the ESC hot based on if you are currently running or not:

Global $RunFlag = False, $i = 0, $Time

HotKeySet("{PAUSE}", "_StartStop")

While 1
    If $RunFlag Then
        If TimerDiff($Time) > 1000 Then
            $i += 1
            ToolTip("$i = " & $i)
            $Time = TimerInit()
        EndIf
    EndIf
    Sleep(20)
WEnd

Func _StartStop()
    $RunFlag = Not $RunFlag
    If $RunFlag Then
        $Time = TimerInit()
        HotKeySet("{ESC}", "panic")
    Else
        HotKeySet("{ESC}")
    EndIf
EndFunc

Func panic()
    Exit
EndFunc   ;==>panic

The ToolTip increments just to show it's running. You can start/stop it with PAUSE. ESC will only exit the script if count is running.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks for the code, it's not working within disable input though... because I want all input except Esc to be disabled. It appears as though this just assigns ESC depending on if it is running or not, which is kind-of what I needed, but what I really nead is to disable all keys except escape. Is there a way to throw an exception for disable input?

Link to comment
Share on other sites

Thanks for the code, it's not working within disable input though... because I want all input except Esc to be disabled. It appears as though this just assigns ESC depending on if it is running or not, which is kind-of what I needed, but what I really nead is to disable all keys except escape. Is there a way to throw an exception for disable input?

Not that I know of, IsPressed("1B") for ESC doesn't work after BlockInput(1):

#include <misc.au3>

BlockInput(1)
ConsoleWrite("Debug: inputs blocked" & @LF)

$Timer = TimerInit()
While TimerDiff($Timer) < 30000 ; 30 seconds to test
    Sleep(50)
    If _IsPressed("1B") Then 
        ConsoleWrite("Debug: ESC was pressed" & @LF)
        ExitLoop
    EndIf
WEnd

BlockInput(0)
ConsoleWrite("Debug: inputs unblocked" & @LF)

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Not that I know of, IsPressed("1B") for ESC doesn't work after BlockInput(1):

#include <misc.au3>

BlockInput(1)
ConsoleWrite("Debug: inputs blocked" & @LF)

$Timer = TimerInit()
While TimerDiff($Timer) < 30000 ; 30 seconds to test
    Sleep(50)
    If _IsPressed("1B") Then 
        ConsoleWrite("Debug: ESC was pressed" & @LF)
        ExitLoop
    EndIf
WEnd

BlockInput(0)
ConsoleWrite("Debug: inputs unblocked" & @LF)

:)

Hehe, that makes me feel all warm inside :P Thanks ;)

P.S. That's why I posted all of my code, though I suppose I could have shortened the GUI and stuff, but...

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...