;Decimal and Hex values of a key pressed     v1.10

;**************************************************************************
;* Written by:  Symantec ASPECT Assist                                       *
;*                                                                           *                                                                             
;* This script file will give the user the option of either capturing data   *
;* in half hour increments, or in 24 hour increments. The Capture file will  *
;* close after a predefined period of inactivity on the port.                *
;*                                                                           *
;* This ASPECT script is intended only as a sample of ASPECT programming.    *
;* Symantec makes no warranty of any kind, express or implied, including     *
;* without limitation, any warranties of merchantability and/or fitness      *
;* for a particular purpose.  Use of this program is at your own risk.       *
;*                                                                           *
;* Technical Support is not provided on this script.                         *                                                                          *
;*****************************************************************************


;**************************************************************************
;* GLOBAL VARIABLES                                                       *
;**************************************************************************

string TheKey, StrAskKey, StrTheKey, StrKeyValAnsi, StrKeyValHex, KeyValHex
integer KeyValAnsi

;**************************************************************************
;*                                                                        *
;* MAIN                                                                   *     
;* The procedure main calls MakeDialogBox to draw the dialbox and set the *
;* proper variables which returns to Main. When a dialog event occurs Main*
;* calls UpDateBox from a WHEN command.                                   *
;*                                                                        *
;* Calls: MakeDialogBox, UpDateBox                                        *
;* Modifies globals: none                                                 *
;*                                                                        *     
;**************************************************************************

proc Main
   MakeDialogBox()                 ; calls the procedure MakeDialogBox
   when DIALOG 0 call UpDateBox    ; when a dialog event ocurrs call UpDateBox
      while 1                      ; loop forever until "when dialog" is called
      endwhile
endproc

;**************************************************************************
;*                                                                        *
;* MAKEDIALOGBOX ()                                                       *
;*                                                                        *
;* This procedure draws the dialog box prompting the user to input a key  *
;* to calculate it's decimal and hexidecimal value. It sets the dialog    *
;* box control variables to be updated later in procedure UpDateBox.      *
;* It then returns to procedure Main.                                     *     
;*                                                                        *
;* Called by: Main                                                        *
;* Modifies globals: StrAskKey, StrTheKey, StrKeyValAnsi, StrKeyValHex,   *
;*                   TheKey                                               *
;*                                                                        *
;**************************************************************************

proc MakeDialogBox
; The next four lines format the text data with the STRFMT command
; and set the control variables to make the dialog box and its controls.
   strfmt StrAskKey "Enter the Key to calculate..."             
   strfmt StrTheKey "The Key pressed is %s  "  TheKey 
   strfmt StrKeyValAnsi "The ASCII Decimal Value is %c  " KeyValAnsi
   strfmt StrKeyValHex "The ASCII Hexidecimal Value is %s  " KeyValHex
   dialogbox 0 43 44 196 116 138 "Key Check Script"         ; make the dialog box
      text 1 2 4 192 8 "Enter a key to find it's Decimal and Hexidecimal values." LEFT
      text 9 2 14 192 8 "Click on (Find Value) " LEFT
      editbox 2 110 35 10 14 TheKey 1
      text 3 2 40 102 12 StrAskKey LEFT
      text 4 2 55 170 8 StrTheKey LEFT
      text 5 2 65 170 8 StrKeyValAnsi LEFT
      text 6 2 75 170 8 StrKeyValHex LEFT
      pushbutton 7 117 96 48 15 "Cancel Script"
      pushbutton 8 34 96 48 15 "Find Value"
   enddialog
endproc

;**************************************************************************
;*                                                                        *
;* UPDATEBOX ()                                                           *
;*                                                                        *
;* This procedure is called when a dialog box event occurs. It takes the  *
;* value from the user input and calculates the ASCII decimal and         *
;* hexidecimal values by STRFMT commands to the variables. Then it updates*
;* the appropriate dialog box control variables to the new values and     *
;* returns to Main. If the dialog event was "7", the script is terminated.*
;*                                                                        *                                                                     
;* Called by: Main                                                        *
;* Modfies globals: KeyValAnsi, KeyValHex                                 *
;*                 StrTheKey, StrKeyValAnsi, StrKeyValHex                 *
;*                                                                        *
;**************************************************************************

proc UpDateBox
integer Event, GoHome=0x09        
   while 1                         ; loop forever
      dlgevent 0 Event             ; get the dialog event
      switch Event                 ; evaluate the event
	 case 2                    ; case if character was entered in editbox
	    strgetc TheKey 0 KeyValAnsi         ; gets integer value of user input string
	    strfmt KeyValHex "%02X" KeyValAnsi  ; uses this integer to get a hex value
	    strfmt StrTheKey "The Key pressed is `" %s `" " TheKey
	    strfmt StrKeyValAnsi "The ASCII Decimal Value is %d " KeyValAnsi
	    strfmt StrKeyValHex "The ASCII Hexidecimal Value is %s " KeyValHex
	    dlgupdate 0 4          ; displays the actual key pressed from TheKey
	    dlgupdate 0 5          ; displays the decimal value from KeyValAnsi
	    dlgupdate 0 6          ; displays the hex value from KeyValHex
	    strcpy TheKey $NULLSTR ; set TheKey (from user input) to a NULL string
	    dlgupdate 0 2          ; clears the user input area with TheKeY (NULL)              
            
   exitwhile                       ; exit while loop and return to Main
	 endcase
	 case 7                    ; if (Cancel Script) button is pressed then,
	    exit                   ; exit the script 
	 endcase
	 case 8                    ; case when (Find Value) button is used
	    sendvkey GoHome        ; returns cusor to data input area
	 endcase   
	 default                   ; default case
	 endcase
      endswitch
   endwhile        
endproc

  
