COBOL捕获箭头按键

时间:2014-02-25 05:28:22

标签: input console cobol

我是COBOL的新手,所以作为一个学习练习(并且只是为了它)我正在尝试制作一个基于小型控制台的连接游戏4.但是我很难找到一种方法听取和读取击键(例如使用箭头键左右移动一块),而不必按下回车键。到目前为止,我发现最好的解决方案是使用Microfocus'增强接受/显示(Adis),允许以我想要的方式使用功能键。我想知道是否有一些我可能错过的东西,或者使用Adis的一种方式,它允许我使用与功能键之外的其他键相同的功能。以下程序(从https://www.microfocus.co.jp/manuals/SE/books/uisckb.htm无耻地复制)演示了我想要的方式使用功能键:

 1$set noosvs mf ans85
 2**********************************************************
 3* Copyright Micro Focus International 2000. All Rights   *
 4* Reserved. This demonstration program is provided for   *
 5* use by users of Micro Focus products and may be used,  *
 6* modified and distributed as part of your application   *
 8* provided that you properly acknowledge the copyright   *
 9* of Micro Focus in this material.                       *
 9**********************************************************
10
11**********************************************************
12*                                                        *
13*                        FUNKEY.CBL                      *
14*                                                        *
15*    This program demonstrates how to decode function    *
16*    keys using the x"af" call.                          *
17*                                                        *
18**********************************************************
19 special-names.
20     crt status is key-status.
21
22 working-storage section.
23 01 flag                        pic 9(2) comp-x value 1.
24 01 user-key-control.
25     05 enable-fn-keys          pic 9(2) comp-x value 1.
26     05 filler                  pic x         value "1".
27     05 first-user-key          pic 9(2) comp-x value 1.
28     05 number-of-keys          pic 9(2) comp-x value 10.
29
30 01 key-status.
31     05 key-type                pic x.
32     05 key-code-1              pic 9(2) comp-x.
33     05 filler                  pic x.
34 01 any-data                    pic x.
35 01 key-code-1-display          pic z9.
36
37 procedure division.
38     perform enable-keys
39     perform accept-function-key
40     perform tell-which-key-was-pressed
41     perform stop-run.
42
43 enable-keys.
44     call x"af" using flag user-key-control.
45
46 accept-function-key.
47     display spaces upon crt
48     display "Press a function key: F1 to F10" at 0505
49     accept any-data at 0540.
50       
51 tell-which-key-was-pressed.
52     evaluate key-type
53      when 0 display "You pressed <Enter>" at 0705
54      when 1
55         move key-code-1 to key-code-1-display
56         display "You pressed function key" at 0705
57         display key-code-1-display         at 0730
58     end-evaluate.
59
60 stop-run.
61     stop run.

3 个答案:

答案 0 :(得分:1)

你准备使用一些非传统的COBOL,在键盘处理方面,S-Lang库是蜜蜂的膝盖。不需要ADIS,但要小心,两人可以和平共处。尝试这个例子将需要GNU Cobol 1.1和libslang(由John E. Davis,jedsoft提供)。

OCOBOL >>SOURCE FORMAT IS FIXED
      *> ***************************************************************
      *> Date:      20090503
      *> License:   Copyright 2009, Brian Tiffin
      *>            licensed for use under the GNU GPLv2
      *> Purpose:   Experimental S-Lang keyboard interface
      *> Tectonics: cobc -x slangkey.cob -lslang
      *> ***************************************************************
       identification division.
       program-id. slangkey.

       data division.
       working-storage section.
       01 thekey               usage binary-long unsigned.
       01 thekm                usage binary-long.
       01 result               usage binary-long.

      *> exit handler address and priority (prio is IGNORED with OC1.1)
       01 install-flag       pic 9 comp-x value 0.
       01  install-params.
           02 exit-addr      usage is procedure-pointer.
           02 handler-prio   pic 999 comp-x.

      *> ***************************************************************
       procedure division.

      *> Initialize low and high level S-Lang terminal routines
       call "SLtt_get_terminfo" end-call
       call "SLkp_init" returning result end-call
       if result equal -1
           display "problem intializing S-Lang tty" end-display
           stop run giving 1
       end-if

       call "SLang_init_tty" using
           by value -1     *> abort char
           by value -1     *> flow ctrl
           by value 0      *> output processing
         returning result
       end-call
       if result equal -1
           display "problem intializing S-Lang tty" end-display
           stop run giving 1
       else
           display "Keyboard in special mode" x"0d" end-display
       end-if

      *> install an exit handler to put terminal back
       set exit-addr to entry "tty-reset"
       call "CBL_EXIT_PROC" using
           install-flag
           install-params
           returning result
       end-call
       if result not equal zero
           display "error installing exit procedure" end-display
       end-if

      *> Not sure?  Have SLang handle ^C or let GNU Cobol take over?
       call "SLang_set_abort_signal" using by value 0 end-call

      *> The demo.  Fetch a key, then fetch a keycode.  4 times.
      *>   SLang terminals display newline as newline.  Need explicit
      *>   CR to get a carriage return.  Hence the x"0d".
      *>   Plus, output is buffered until line terminators.
       display
           "Tap a normal key, then tap a 'special' key, ie F1, 4 times"
           x"0d"
       end-display
       perform 4 times
           call "SLang_getkey" returning thekey end-call
           display thekey space with no advancing end-display
           call "SLkp_getkey" returning thekm end-call
           display thekm x"0d" end-display
       end-perform

      *> Exit handler will take care of resetting terminal
       goback.


      *> ***************************************************************
      *> Exit procedure to ensure terminal properly reset
      *> ***************************************************************
       entry "tty-reset".
       call "SLang_reset_tty" end-call
       display "exit proc reset the tty" end-display
       goback.

       end program slangkey.

答案 1 :(得分:1)

派对有点迟了但是:

可以在https://supportline.microfocus.com/Documentation/books/sx51/sx51indx.htm找到ADIS的文档 - 查找“字符用户界面”,特别是“通过ADIS进行键盘处理”部分。代码中的“enable-function-keys”段使能功能键从F1到F10。你需要做的是改变光标键的功能,这是ADIS键,你需要这样做

01 adis-key-control.
   05 enable-adis-keys        pic 9(2) comp-x value 1.
   05 filler                  pic x         value "2".
   05 first-adis-key          pic 9(2) comp-x value 3.
   05 number-of-adis-keys     pic 9(2) comp-x value 8.

然后添加行

call x"af" using flag adis-key-control.

到段落enable-function-keys。这将允许您向左,向右,向上和向下捕捉光标,以及Home,tab,backtab和End。

答案 2 :(得分:0)

我没有Micro Focus COBOL,但是快速互联网搜索似乎表明您选择的示例通过使用术语function-keys引入了一些混淆,并显示通过按function-keys收到的值。

使用函数键可能是最简单的示例,因为键值是1到10,因此不需要从键值转换到您理解的键。它显示3,你知道它意味着F3。

您展示的示例中唯一的线索是05 number-of-keys pic 9(2) comp-x val。如果x'af'CALL使用的密钥数量是可配置的,那么它可以更改,那么,密钥本身可能会被更改。

你问ADIS(Micro Focus的Extended ACCEPT and DISPLAY)?是。这一切都在ADIS内。所有光标键都是Standard Adis Key Functions

的一部分

如果您运行示例程序并按箭头键而不是功能键,会发生什么?

我搜索了micro focus user interface manual并找到了足够的信息,因此必须知道您拥有哪种特定的Micro Focus产品。