Reading from keyboard KAREL

  • Hello everybody,


    I would like to ask whether it is possible or not to use KAREL to read a STRING variable from user panel? My problem is that I want to make a program which will allow me to switch to a user screen and then to read a string from TeachPendant (like you may add annotations/comments to a register or to a program). I've already tried to use READ function, but I have no idea how to read a character or a word.


    I would be grateful for any help.

  • This right out of the manual did you try this yet.


    PROGRAM readkb
    %NOLOCKGROUP
    %ENVIRONMENT flbt
    %ENVIRONMENT uif
    %INCLUDE FR:eklevkmsk
    VAR
    file_var: FILE
    key: INTEGER
    n_chars_got: INTEGER
    pop_index: INTEGER
    status: INTEGER
    str: STRING[1]
    BEGIN
    -- Suspend any outstanding TP Keyboard reads
    PUSH_KEY_RD(’TPKB’, 255, pop_index, status)
    IF (status = 0) THEN
    WRITE (CR, ’pop_index is ’, pop_index)
    ELSE
    WRITE (CR, ’PUSH_KEY_RD status is ’, status)
    ENDIF
    -- Open a file to TP Keyboard with PASALL and FIELD attributes
    -- and NOECHO
    SET_FILE_ATR(file_var, ATR_PASSALL)
    SET_FILE_ATR(file_var, ATR_FIELD)
    OPEN FILE file_var (’RW’, ’KB:TPKB’)
    -- Read a single key from the TP Keyboard
    READ_KB(file_var, str, 1, 0, kc_display+kc_func_key+kc_keypad+
    kc_enter_key+kc_lr_arw+kc_ud_arw+kc_other, 0, ’’,
    n_chars_got, key, status)
    IF (status = 0) THEN
    WRITE (CR, ’key is ’, key, ’, n_chars_got = ’, n_chars_got)
    ELSE
    WRITE (CR, ’READ_KB status is ’, status)
    ENDIF
    CLOSE FILE file_var
    -- Resume any outstanding TP Keyboard reads
    POP_KEY_RD(’TPKB’, pop_index, status)
    IF (status <> 0) THEN
    WRITE (CR, ’POP_KEY_RD status is ’, status)
    ENDIF
    END readkb

  • Thank you for your response, yet this program still doesn't solve my problem as it is only returning somehow converted keys to numbers. All I need is a feature which will make a TP's keyboard pop up on a user screen. This will allow end-user to enter his own strings from TP as I do not want operator to be able to edit string registers manually.

  • I took a Karel class back in May & actually asked the question about forcing the keyboard. The answer given to me was that there was no Karel command to do so. That really surprised me because that would be extremely helpful.

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