Sign in to follow this  
Followers 0
ausssieautomate

_IsPressed Not Working

3 posts in this topic

#1 ·  Posted (edited)

Heyas,

Toying around with GUI's again came across a snag. The IsPressed(Enter Key) doesn't work if I have the mouse 'focused' on a radio button at the time, rather than the textbar. Also is there more elegant way to implement my error checking than using an "errorflag"? Any assistance would be appericated.

Source Code Below:

#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstants.au3>

#include <GuiButton.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#include <Misc.au3>

HotKeySet("{ESC}", "Terminate")

Opt("WinTitleMatchMode", 2)

;Getting Info from webpage.

;Rule that allows only one instance of the script.

if _Singleton(@ScriptName, 1) = 0 Then

Msgbox(0,"Error","An instance of this script is already running!")

Exit

EndIf

;Declaring Global Variables

Global $errorflag = 0

Global $UserInput = ""

;Declaring Local Variables

Local $Unknown = ""

Local $TestRadio1 = ""

Local $TestRadio2 = ""

Local $TestRadio3 = ""

Local $TestRadio4 = ""

;Creating the structure of the primary GUI

$Form1 = GUICreate("CMD Command Generator", 307, 354, 192, 124)

$Label1 = GUICtrlCreateLabel("Enter No", 16, 72, 119, 20)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

$Input1 = GUICtrlCreateInput("", 144, 71, 129, 21)

$Label2 = GUICtrlCreateLabel("Radio Button Type ", 80, 112, 153, 24)

GUICtrlSetFont(-1, 12, 800, 4, "MS Sans Serif")

$Radio1 = GUICtrlCreateRadio("Unknown", 16, 152, 161, 17)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

$Radio2 = GUICtrlCreateRadio("Radio1", 16, 184, 161, 17)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

$Radio3 = GUICtrlCreateRadio("Radio2", 16, 216, 161, 17)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

$Radio4 = GUICtrlCreateRadio("Radio3", 16, 246, 193, 17)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

$Radio5 = GUICtrlCreateRadio("Radio4", 16, 278, 209, 17)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

$Button2 = GUICtrlCreateButton("Enter Command", 72, 312, 145, 25, $WS_GROUP)

GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

GUISetState(@SW_SHOW)

Gui()

Func Gui()

GuiSetState(@SW_ENABLE, $form1)

;Run The GUI until the dialogue is closed

While 1

;Declare Inital Variable

Local $WinAct = WinActive("CMD Command Generator")

$Msg = GUIGetMsg()

;Poll the GUI for any changes- Button Presses, changes in text...

if (_isPressed("0D") AND $WinAct = 1) Then

$msg = $Button2

EndIf

Switch $Msg

Case $Button2

;Resetting the ErrorFlag

$errorflag = 0

;Getting the States of the Radio Buttons

$Unknown = _GUICtrlButton_GetState($radio1)

$TestRadio1 = _GUICtrlButton_GetState($radio2)

$TestRadio2 = _GUICtrlButton_GetState($radio3)

$TestRadio3 = _GUICtrlButton_GetState($radio4)

$TestRadio4 = _GUICtrlButton_GetState($radio5)

;ReadingInput

$inputx = GUICtrlRead($input1)

;Peforming Validation Checks

If ($inputx = "" OR stringLen($inputx) < 10) Then

msgbox(0, "Input Error:", "You to enter a Mobile No to Search.")

$errorflag = 1

EndIf

if($errorflag = 0) Then

CMD()

EndIf

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

EndFunc

Func CMD()

$UserInput = GUICtrlRead($input1)

WinActivate("cmd.exe")

if $Unknown = 1 Then

Send("ipconfig")

Send("{ENTER}")

EndIf

if $TestRadio1 = 1 Then

Send("ping www.google.com")

Send("{ENTER}")

EndIf

if $Testradio2 = 1 Then

Send("nslookup")

Send("{ENTER}")

EndIf

if $TestRadio3 = 1 Then

Send("ping 127.0.0.1")

Send("{ENTER}")

EndIf

if $TestRadio4 = 1 Then

Send("ser CR001000")

Send("{ENTER}")

EndIf

Gui()

EndFunc

Func Terminate()

Exit 0

EndFunc

Thanks :D

Edited by ausssieautomate

Frequent sufferer of ID10T Syndrome and CRAFT (Can't Remember A "BLEEP" Thing)

Share this post


Link to post
Share on other sites



use GuiSetAccelerators

Share this post


Link to post
Share on other sites

Heya Guys,

Cheers for those tips I'll research those functions.

Thx.


Frequent sufferer of ID10T Syndrome and CRAFT (Can't Remember A "BLEEP" Thing)

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