Operation (cont) [ Micro Focus COBOL System Reference, Volume 1 ] MPE/iX 5.0 Documentation
Micro Focus COBOL System Reference, Volume 1
Operation (cont)
Keyboard Handling Via Adis (cont)
Lock Key Handling.
Adis provides a number of routines to enable an applicaton to make use of
the lock key capabilities of a keyboard. These routines are described in
the following sections.
Determining Available Lock Keys.
This routine enables you to find out which of the lock keys are
detectable as unique events.
Use the following call to determine which lock keys are available to your
program:
call x"AF" using adis-function
adis-parameter
where adis-function and adis-parameter are defined in the Working-Storage
Section of your program as follows:
01 adis-function pic 9(2) comp-x
01 adis-parameter pic 9(4) comp-x.
where:
adis-function must be 45.
adis-parameter returns which lock keys are available to your
program. The 16 bits in adis-parameter refer to lock
keys as follows, with bit 0 the least significant:
Bit Associated Key
-------------------------------
4 - 15 Reserved
3 Ins Lock
2 Caps Lock
1 Num Lock
0 Scroll Lock
A value of 1 for any particular bit indicates that the associated key is
uniquely detectable.
Detecting the Current State of the Lock Keys.
This routine enables you to determine which, if any, of the lock keys are
currently active. For example, the Scroll Lock key is active when scroll
lock is on.
Use the following call to determine which of the lock keys are currently
active:
call x"AF" using adis-function
adis-parameter
where adis-function and adis-parameter are defined in the Working-Storage
Section of your program as follows:
01 adis-function pic 9(2) comp-x.
01 adis-parameter pic 9(4) comp-x.
where:
adis-function must be 47.
adis-parameter returns which of the lock keys are currently pressed.
The 16 bits in adis-parameter refer to lock keys as
follows, with bit 0 the least significant:
Bit Associated Key
4 - 15 Reserved
3 Ins Lock
2 Caps Lock
1 Num Lock
0 Scroll Lock
A value of 1 for any particular bit indicates that the associated key is
currently active.
Enabling or Disabling Lock Keys.
By default, all of the lock keys are disabled during an ACCEPT operation,
or the x"AF" call used to obtain a key. However, this routine enables
you to enable or disable the lock keys dynamically.
Use the following call to enable or disable lock keys:
call x"AF" using adis-function
adis-parameter
where adis-function and adis-parameter are defined in the Working-Storage
Section of your program as follows:
01 adis-function pic 9(2) comp-x
01 adis-parameter.
03 lock-key-setting pic 9(2) comp-x.
03 filler pic x value "4".
03 first-lock-key pic 9(2) comp-x.
03 number-of-lock-keys pic 9(2) comp-x.
where:
adis-function must be 1.
lock-key-setting defines the action of the keys affected, as
follows:
0 - The keys are disabled. If the key is
pressed it will be ignored.
1 - The keys are enabled.
first-shift-key is the number of the first key to be affected. The
keys to enable are numbered as follows:
0 - Ins Lock
1 - Caps Lock
2 - Num Lock
3 - Scroll Lock
number-of-lock- is the number of consecutive keys to be affected.
keys
Get Single Character Routine
This routine enables you to get a single key from the keyboard. It uses
Adis itself, so all of the function keys supported by Adis are supported.
The routine only reads the keyboard and so does not echo the key to the
screen.
The call used is:
call x"AF" using get-single-char-func
key-status
where get-single-char-func and key-status are defined in the
Working-Storage Section of your program as follows:
01 get-single-char-func pic 9(2) comp-x value 26.
01 key-status.
03 key-type pic x.
03 key-code.
05 key-code-1 pic 9(2) comp-x.
05 key-code-2 pic 9(2) comp-x.
The values returned in key-status are the same as those described
previously, except that a value of "0" is never returned in key-type by
this call. The carriage return key returns a value of "2" in key-type
and a value of 2 in key-code-1.
The values returned in key-status are as follows:
key-type key-code-1
-------------------------------------------------------
"1" Returns the number of the user
function pressed.
"2" Returns the number of the Adis key
pressed. No mapping of keys occurs
in this call. Therefore, the number
returned is the number of the actual
key pressed.
"3" Returns the ASCII code of the 8 bit
data key pressed.
"4" Returns the first byte of the 16 bit
data key pressed. The second byte
is contained in key-code-2. This is
only applicable on machines that
support double-byte characters.
"5" The number of the shift key pressed.
"6" The number of the lock key pressed.
"9" Error condition. Values are:
8 Disabled character. The data key
pressed is disabled.
9 Invalid keystroke. A function key
has been pressed that is not defined
in either the user or Adis function
key list.
Example.
call x"AF" using get-single-char-func
key-status
evaluate key-type
when "1"
* User function key pressed. Do required
* action depending on value in key-code-1.
when "2"
* Adis function key pressed. Do required
* action depending on value in key-code-1.
when "3"
* Data key pressed. Do required action
* depending on the ASCII code in key-code-1.
when "4"
* Double byte data key pressed. Do required
* action depending on the 16-bit character in
* key-code.
when "5"
* Shift key pressed/released. Do required action
* depending on
* value in key-code-1
when "6"
* Lock key state changed. Do required action depending
* on value in key-code-1
when "9"
* Invalid or disabled key. Do required action.
End-evaluate.
Sample Program
The following is an example of how to write programs that make use of
function keys. It assumes that Escape is available, but any other
function key can be selected either by pressing the function key or by
pressing a slash (/) followed by the first letter of the option.
$set ans85
**************************************************
* This program assumes that the default
* configuration has been selected using Adiscf.
***************************************************
special-names.
cursor is cursor-position
crt status is key-status.
data division.
working-storage section.
**************************************************
* Parameters to be used for the x"AF" calls.
**************************************************
01 set-bit-pairs pic 9(2) comp-x value 1.
01 get-single-character pic 9(2) comp-x value 26.
01 enable-esc-and-f1.
03 filler pic 9(2) comp-x value 1.
03 filler pic x value "1".
03 filler pic 9(2) comp-x value 0.
03 filler pic 9(2) comp-x value 2.
01 disable-all-other-user-keys.
03 filler pic 9(2) comp-x value 0.
03 filler pic x value "1".
03 filler pic 9(2) comp-x value 2.
03 filler pic 9(2) comp-x value 126.
01 enable-slash-key.
03 filler pic 9(2) comp-x value 1.
03 filler pic x value "3".
03 filler pic x value "/".
03 filler pic 9(2) comp-x value 1.
**************************************************
* Status returned after termination of an ACCEPT.
**************************************************
01 key-status.
03 key-type pic x.
03 key-code-1 pic 9(2) comp-x.
03 key-code-1-x redefines key-code-1 pic x.
03 key-code-2 pic 9(2) comp-x.
**************************************************
* Cursor-Position is returned by ADIS containing
* the position of the cursor when the ACCEPT was
* terminated.
***************************************************
01 cursor-position.
03 cursor-row pic 99.
03 cursor-column pic 99.
**************************************************
* Work areas used by the program.
**************************************************
01 work-areas.
03 wa-name pic x(30).
03 wa-address-line-1 pic x(40).
03 wa-address-line-2 pic x(40).
03 wa-address-line-3 pic x(40).
03 wa-address-line-4 pic x(40).
03 wa-age pic 999 value 0.
01 exit-flag pic 9(2) comp-x value 0.
**************************************************
* Screen Section.
**************************************************
screen section.
01 main-screen.
03 blank screen.
03 line 2 column 27
value "Typical Data Entry Screen".
03 line 3 column 27
value "-------------------------".
03 line 5 column 1 value "name [".
03 pic x(30) using wa-name highlightprompt " ".
03 value "]".
03 line 7 column 1 value "address [".
03 pic x(40) using wa-address-line-1 highlight prompt " ".
03 value "]".
03 line 8 column 1 value " [".
03 pic x(40) using wa-address-line-2 highlight prompt " ".
03 value "]".
03 line 9 column 1 value " [".
03 pic x(40) using wa-address-line-3 highlight prompt " ".
03 value "]".
03 line 10 column 1 value " [".
03 pic x(40) using wa-address-line-4 highlight prompt " ".
03 value "]".
03 line 12 column 1 value "age [".
03 pic zz9 using wa-age highlight prompt " ".
03 value "]".
03 line 20 column 1 value
"------------------------------------
"----------------------------------------".
03 line 21 column 1 value "f1" highlight.
03 value "=/help".
03 column 75 value "esc" highlight.
03 value "ape".
01 help-screen.
03 blank screen.
03 line 1 column 34 value "help screen".
03 line + 1 column 34 value "-----------".
03 line 4 value "escape" highlight.
03 value " leave this program.".
03 line 6 column 1 value "f1 or /h" highlight.
03 value " obtains this screen.".
03 line 8 column 1
value "use cursor keys to move around ".
03 value "the fields on the screen".
03 value "enter will".
03 line + 1 column 1 value "accept the data ".
03 value " present new blank form to fill in.".
03 line 24 column 25
value "press any key to continue ...".
**************************************************
* Procedure Division.
**************************************************
procedure division.
entry-point section.
* First we want to ensure that the keys are enabled as we want
* them. Enable the Escape and F1 keys.
call x"AF" using set-bit-pairs
enable-esc-and-f1
* disable every other user function key.
call x"AF" using set-bit-pairs
disable-all-other-user-keys
* set up "/" key to act as a function key and terminate
* the ACCEPT operation.
call x"AF" using set-bit-pairs enable-slash-key
* Now ensure that the cursor position will be returned when an
* ACCEPT is terminated. Setting to row 1, column 1 will ensure
* that the cursor will be initially positioned at the start of
* the first field.
move 1 to cursor-row
move 1 to cursor-column
* Loop until the Escape key is pressed.
perform until exit-flag = 1
display main-screen
accept main-screen
evaluate key-type
when "0"
* The ACCEPT operation terminated normally; that is the Enter key
* was pressed. In this case, we simply blank out the work areas
* and restart in the first field.
initialize work-areas
move 1 to cursor-row
move 1 to cursor-column
when "1"
* A user function key has been pressed. This will either be
* Escape or F1 as all others have been disabled.
if key-code-1 = 0
* Escape has been pressed, so we wish to leave the program.
move 1 to exit-flag
else
* F1 has been pressed so display the help screen.
perform display-help-screen
end-if
when "3"
* A data key has terminated the ACCEPT operation. It must be "/"
* as no other keys have been enabled to do this. Now get the
* next character to see if "H" or "h" has been pressed.
call x"AF" using get-single-character
key-status
if key-type = "3" and
(key-code-1-x = "h" or
key-code-1-x = "H")
perform display-help-screen
end-if
end-evaluate
end-perform
stop run.
display-help-screen section.
* Display the help screen and then wait for a key to be pressed.
display help-screen
call x"AF" using get-single-character
key-status.
Mouse Handling Via Adis
This section describes how to use a mouse with programs that use Adis to
handle the screen and keyboard on DOS, Windows and OS/2 environments. It
shows you how to activate the mouse, and use it in the Adis ACCEPT
operation. Mouse handling is not available in UNIX environments. (DOS,
Windows and OS/2)
Using the Mouse.
This section describes how to access the mouse for use in screen handling
in this COBOL system. The mouse is not active by default, so the
routines below must be called to allow the mouse to be used. The mouse
is only available if the relevant mouse drivers, supplied with the mouse
or the operating system, are installed.
Having the mouse pointer enabled during an Adis ACCEPT statement allows
your user to alter the current input field by moving the mouse pointer
over another field and pressing the Left button on the mouse. This
results in the text cursor being moved to the mouse pointer position.
The Left button on the mouse is treated as Adis key number 27 and behaves
in the same way as all other Adis keys. See the section Keyboard
Handling Via Adis for details on using the Adis keys. The example at the
end of this section shows how the action of the leftmost button can be
changed so the mouse can be used to terminate an accept operation.
Once the mouse is active (and enabled) the mouse cursor moves on the
screen when the mouse is moved. This happens independently of any Adis
operations. Adis takes notice of the mouse only when a mouse button is
pressed. However, the program can determine the position of the mouse at
any time using the appropriate routine described below.
Activating or Terminating Use of a Mouse.
You control whether a mouse driver is in use or not as follows:
call x"AF" using use-mouse-function
usage-parameter
where use-mouse-function and usage-parameter are defined in the
Working-Storage Section of your program as follows:
01 use-mouse-function pic 9(2) comp-x value 64.
01 usage-parameter pic 9(2) comp-x.
where usage-parameter should be set as follows:
0 Terminate mouse activity. The mouse pointer is deleted and no
further mouse action is possible.
1 Activate the mouse. This activates the mouse driver and draws
the mouse pointer.
On return from this call, use-mouse-function contains 255 if no mouse is
present.
Example.
The following code activates the mouse:
move 1 to usage-parameter
call x"AF" using use-mouse-function
usage-parameter
Enabling or Disabling the Mouse.
You disable or re-enable the mouse as follows:
call x"AF" using enable-mouse-function
enable-parameter
where enable-mouse-function and enable-parameter are defined in the
Working-Storage Section of your program as follows:
01 enable-mouse-function pic 9(2) comp-x value 66.
01 enable-parameter pic 9(2) comp-x.
where enable-parameter should be set as follows:
0 Disables the mouse. The mouse pointer is hidden and all mouse
movement and button presses are are ignored until the mouse is
reactivated.
1 Re-enables the mouse. This redraws the mouse pointer; that is,
makes it visible, and re-enables the ability to detect mouse
movement and button presses.
Example.
The following code disables the mouse:
move 0 to enable-parameter
call x"AF" using enable-mouse-function
enable-parameter
Returning Mouse Status and Position.
You query the position of the mouse pointer and the status of the mouse
driver as follows:
call x"AF" using get-mouse-details
mouse-details
where get-mouse-details and mouse-details are defined in the
Working-Storage Section of your program as follows:
01 get-mouse-details pic 9(2) comp-x value 67.
01 mouse-details.
03 mouse-x-position pic 9(4) comp-x.
03 mouse-y-position pic 9(4) comp-x.
03 mouse-status pic 9(4) comp-x.
where the bytes returned in mouse-status have the following meanings:
Bit Value Event Action
--------------------------------------------------------------
0 1 Mouse moved.
1 2 Button 1 pressed.
2 4 Button 2 pressed.
3 8+ Button 3 pressed.
Example.
The following code displays the mouse pointer position:
call x"AF" using get-mouse-details
mouse-details
display "mouse-x-position is " at line 1 column 1
display mouse-x-position at line 1 column 22
display "mouse-y-position is " at line 2 column 1
display mouse-y-position at line 2 column 22
Example of Using a Mouse.
The following code sets up the mouse to act as a function key. Pressing
the Left mouse button terminates the ACCEPT operation and causes the the
mouse coordinates to be displayed. The data items are as defined in the
section Enabling or Disabling the Adis Keys and in the details of the
routines above.
* Activate the mouse
move 1 to usage-parameter
call x"AF" using use-mouse-function
usage-parameter
* Set the mouse (key 27) to act as a function key
move 3 to adis-key-setting
move 27 to first-adis-key
move 1 to number-of-adis-keys
call x"AF" using set-bit-pairs
adis-key-control
accept data-item at 0101
if key-type = "2" and key-code-1 = 27
display "the mouse terminated the accept"
call x"AF" using get-mouse-details
mouse-details
display "mouse-x-position is " at line 3 column 1
display mouse-x-position at line 3 column 22
display "mouse-y-position is " at line 4 column 1
display mouse-y-position at line 4 column 22
end-if
* Terminate the mouse
move 1 to usage-parameter
call x"AF" using use-mouse-function
usage-parameter
MPE/iX 5.0 Documentation