Sign in to follow this  
Followers 0
tobyb

press enter key or click button

3 posts in this topic

alright i'm not sure if this belongs under gui posts or general sorry if i'm in the wrong spot.

i've only been working with autoit for a few months so i'm still a little new. i've been searching the forums and the help guide and can't seem to come up with an answer so i'm resorting to posting for help.

i have simple script that i'd like to allow you to type in the information and then either press the enter key on the keyboard or click the gui "submit" button.

the only thing i've found is the _IsPressed function but using it i can only get it to do one or the other. in other words you can only press enter on the keyboard and the gui button doesn't work or vice versa. i'm sure its something in my while loop to check if enter was pressed or not. i'm just not sure what. any help would be greatly appreciated.

heres a sample of my code.

CODE

Break(1)

#include <GuiConstants.au3>

#include <Misc.au3>

$find = ":"

$replace = "$"

$eqpc = ""

$dll = DllOpen("user32.dll")

;create gui pc query box

$Query = GUICreate("Remote Reg Scan", 300, 125)

GUISetIcon("c:\windows\system32\remotepg.dll", 0)

GuiSetBkColor(0xffffff)

TraySetIcon("c:\windows\system32\remotepg.dll", 0)

TrayTip("Reg Scan", "please be patient as scan runs", 0)

$qpc = GUICtrlCreateLabel("Enter the PC to scan?", 10, 20, 110, 40)

$Input_qpc = GuiCtrlCreateInput("", 135, 20, 140, 20)

GuiCtrlSetData($Input_qpc, "")

$button1 = GuiCtrlCreateButton("Enter", 110, 80, 75, 20)

GuiSetState()

;check if enter was pressed

While 1

Sleep (250)

If _IsPressed("0D",$dll) Then

ControlClick("Remote Reg Scan", "Enter the PC to scan?",5,1,37,9)

ExitLoop

Else

ExitLoop

EndIf

WEnd

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $button1

$eqpc = GUICtrlRead($Input_qpc)

GuiCtrlSetData($Input_qpc, $eqpc)

ExitLoop

EndSelect

Wend

If $eqpc = "" Then

Exit

EndiF

DllClose($dll)

$right = StringRight($eqpc, 4)

$reg1 = regread("\\" & $eqpc & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SMS\Client\Configuration\Client Properties","NOIDMIF Directory")

$reg2 = regread("\\" & $eqpc & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters","srvcomment")

$reg3 = regread("\\" & $eqpc & "\HKEY_LOCAL_MACHINE\SOFTWARE\Symantec\SharedDefs", "DEFWATCH_10")

$reg3right = StringRight($reg3, 12)

$reg1ret = StringReplace($reg1,$find,$replace)

$path = "\\" & $eqpc & "\" & $reg1ret

$file1 = FileOpen("c:\temp\" & $eqpc & ".txt", 2)

filewriteline($file1, "you are connected to pc -" & $eqpc & @crlf)

filewriteline($file1, "the virus definition date is -" & $reg3right & @crlf)

filewriteline($file1, "registry 1 read -" & $reg1 & @crlf)

filewriteline($file1, "registry 2 read -" & $reg2 & @crlf)

filewriteline($file1, "reg return -" & $reg1ret & @crlf)

filewriteline($file1, "path -" & $path & @crlf)

exit

thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

tobyb - I'm not sure if this does what you want it to because I can't test this script on my machine. But there are ways your script can discover if the enter key was pressed. I modified your code to check for a press of the Enter key in both loops:

#include <GuiConstants.au3>
#include <Misc.au3>

    HotKeySet("{ENTER}", "EnterWasPressed")
    $enterSwitch = 0

$find = ":"
$replace = "$"
$eqpc = ""
;$dll = DllOpen("user32.dll")

;create gui pc query box
$Query = GUICreate("Remote Reg Scan", 300, 125)
GUISetIcon("c:\windows\system32\remotepg.dll", 0)
GUISetBkColor(0xffffff)
TraySetIcon("c:\windows\system32\remotepg.dll", 0)
TrayTip("Reg Scan", "please be patient as scan runs", 0)
$qpc = GUICtrlCreateLabel("Enter the PC to scan?", 10, 20, 110, 40)
$Input_qpc = GUICtrlCreateInput("", 135, 20, 140, 20)
GUICtrlSetData($Input_qpc, "")
$button1 = GUICtrlCreateButton("Enter", 110, 80, 75, 20)

GUISetState()

;check if enter was pressed
While 1
    Sleep(100)
    If $enterSwitch = 1 Then
        ControlClick("Remote Reg Scan", "Enter the PC to scan?", 5, 1, 37, 9)
        ExitLoop
    Else
        ExitLoop
    EndIf
WEnd
$enterSwitch = 0

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button1 Or $enterSwitch = 1
            $eqpc = GUICtrlRead($Input_qpc)
            GUICtrlSetData($Input_qpc, $eqpc)
            ExitLoop
    EndSelect
WEnd

If $eqpc = "" Then
    Exit
EndIf

;DllClose($dll)

$right = StringRight($eqpc, 4)
$reg1 = RegRead("\\" & $eqpc & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SMS\Client\Configuration\Client Properties", "NOIDMIF Directory")
$reg2 = RegRead("\\" & $eqpc & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters", "srvcomment")
$reg3 = RegRead("\\" & $eqpc & "\HKEY_LOCAL_MACHINE\SOFTWARE\Symantec\SharedDefs", "DEFWATCH_10")
$reg3right = StringRight($reg3, 12)
$reg1ret = StringReplace($reg1, $find, $replace)
$path = "\\" & $eqpc & "\" & $reg1ret
$file1 = FileOpen("c:\temp\" & $eqpc & ".txt", 2)

FileWriteLine($file1, "you are connected to pc -" & $eqpc & @CRLF)
FileWriteLine($file1, "the virus definition date is -" & $reg3right & @CRLF)
FileWriteLine($file1, "registry 1 read -" & $reg1 & @CRLF)
FileWriteLine($file1, "registry 2 read -" & $reg2 & @CRLF)
FileWriteLine($file1, "reg return -" & $reg1ret & @CRLF)
FileWriteLine($file1, "path -" & $path & @CRLF)

Exit

Func EnterWasPressed()
    $enterSwitch = 1
;HotKeySet("{ENTER}");disables this hot key
EndFunc

Alternative to the above, the following change to your code is a tactic that works for me. It should make the $button1 the default button for your GUI and so if user hits the Enter key, it is as if he clicked the button:

$button1 = GUICtrlCreateButton("Enter", 110, 80, 75, 20)
GuiCtrlSetState(-1, 512)

You do not need _IsPressed for this script, that I can see. And I don't see why you need to open and close the user32.dll.

Edited by Squirrely1

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

Alternative to the above, the following change to your code is a tactic that works for me. It should make the $button1 the default button for your GUI and so if user hits the Enter key, it is as if he clicked the button:

$button1 = GUICtrlCreateButton("Enter", 110, 80, 75, 20)
GuiCtrlSetState(-1, 512)

You do not need _IsPressed for this script, that I can see. And I don't see why you need to open and close the user32.dll.

thanks Squirrely1

the bottom one works for me.

the simpler the better in my opinion.

Share this post


Link to post
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
Sign in to follow this  
Followers 0