Guidance
指路人
g.yi.org
Software / Reginald / Examples / Keys.rex

Register 
新用户注册
Search 搜索
首页 
Home Home
Software
Upload

  
/* An example of a window with the KEYS Flag set. We simply print
 * out each key combo as the user presses it.
 */

ADDRESS null

/* Trap HALT and SYNTAX in any scripts we call which don't
 * trap HALT or SYNTAX themselves.
 */
OPTIONS 'TRAP'

/* Trap SYNTAX/ERROR/HAT, and ask for ERROR raising */
SIGNAL ON HALT
SIGNAL ON SYNTAX
SIGNAL ON ERROR
CALL RXERR('ERROR|DISPLAY')


/* ====================== 'Main Window' ======================= */
/* First Group is TEXT */
rxtype.1 = 'TEXT'

/* Default */
rxflags.1 = 'NOBORDER'

/* Text lines */
rxlabel.1 = "Press a key on the keyboard:|"

/* PhrasesPerLine, X, Y, WidthOfPhrase, BetweenPhrases */
rxpos.1 = '1 10 1 0 0'

/* Use another TEXT Group to display the key */
rxtype.2 = 'TEXT'

/* Default */
rxflags.2 = 'NOBORDER'

/* Text lines */
rxlabel.2 = '|'

/* PhrasesPerLine, X, Y, WidthOfPhrase, BetweenPhrases. Note that
 * we deliberately set WidthOfPhrase non-0 to allow enough width to accomodate
 * a range of text
 */
rxpos.2 = '1 10 20 198 0'

/* Size and position */
rx = ''
CALL RXCREATE('RX', 2, 'Main Window', 'NOCLOSE|KEYS|TAB')

DO FOREVER
   /* Do user interaction. We go to sleep while user manipulates the window,
    * until such time as he presses ESC or ENTER if the window's RESULT Flag
    * is set, or tries to close a window using its CLOSE BOX, or uses a RESULT
    * Group, or uses some Group with its REPORT Flag set, or presses a key if the
    * window's KEYS Flag is set, or the timer times out
    */
   CALL RXMSG()

   /* RXWIND now specifies which window woke us up. The window is still
    * there because we specified NOCLOSE. Even if we hadn't specified that,
    * the window would still be there if what caused RXMSG to return was a user
    * pressing a key. (The exception to this would be the ESC and ENTER keys
    * if we had set the window's RESULT Flag too). NOTE: *None* of the VAL
    * variables, nor the dimensions string for that window have been setup if
    * what caused RXMSG() to return was a user pressing a key. (The exception
    * to this would be the ESC and ENTER keys if we had set both the window's
    * RESULT and SETVAL Flags)
    */

   /* Window's CLOSE BOX */
   IF rxid == '' THEN SIGNAL HALT

   /* Did he press a key? If so, then RXID is not a numeric string and not an empty string */
   IF DATATYPE(rxid, 'NUM') == 0 THEN DO

        text = ""

        /* See what qualifier keys were held down and convert these to more descriptive names */
        IF LEFT(rxid, 1) == 'A' THEN text = 'ALT '
	IF SUBSTR(rxid, 2, 1) == 'C' THEN text = text || 'CTRL '
	IF SUBSTR(rxid, 3, 1) == 'S' THEN text = text || 'SHIFT '

	/* Is it an ascii (ie, printable key)? If so, then it is just a single character */
	IF LENGTH(rxsubid) == 1 THEN DO
	    IF rxsubid = ' ' THEN rxsubid = 'SPACE' /* Just so that we see something for a SPACE */
	END

	text = text || rxsubid

	/* Print out the qualifiers and key name */
	CALL RXSET(,'VALUE', text, 2, 1)
   END

/* Do another message loop */
END





/* ==================== Error Handling ====================== */
syntax:
    CALL RXSAY(CONDITION('D') || '0D0A0D0A'x || SOURCELINE(sigl),,'Error '||condition('E')||' at line '||sigl)

halt:
error:
    /* NOTE: CONDITION('D') fetches error message. CONDITION('E') fetches the
     * error number. SIGL is the line number where the error occurred.
     * Rexx Dialog has already displayed a message since we specified DISPLAY
     * option.
     */
    CALL RXMSG(, 'END')
    EXIT
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2017-6-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-18 23:35:07