Loading ...
Sorry, an error occurred while loading the content.

getchar(0)/getchar(1) doesn't return 27(ESC)

Expand Messages
  • mattn
    Hi list. function! s:getchar() while 1 let key = getchar(0) if key != 0 break endif endwhile echo key endfunction call s:getchar() When run script above and
    Message 1 of 7 , May 13, 2014
    • 0 Attachment
      Hi list.

      function! s:getchar()
      while 1
      let key = getchar(0)
      if key != 0
      break
      endif
      endwhile
      echo key
      endfunction
      call s:getchar()

      When run script above and type ESC, it should show 27. But doesn't. vgetc() doesn't return ESC key code 27. So I wrote a patch to use vgetc_any() instead of vgetc().

      https://gist.github.com/mattn/5fd341c1875b34730dfa

      Thanks.
      - Yasuhiro Matsumoto

      --
      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/d/optout.
    • Bram Moolenaar
      ... Thanks. Did you check that it still works to obtain a special key? -- If you feel lonely, try schizophrenia. /// Bram Moolenaar -- Bram@Moolenaar.net --
      Message 2 of 7 , May 14, 2014
      • 0 Attachment
        Yasuhiro Matsumoto wrote:

        > function! s:getchar()
        > while 1
        > let key = getchar(0)
        > if key != 0
        > break
        > endif
        > endwhile
        > echo key
        > endfunction
        > call s:getchar()
        >
        > When run script above and type ESC, it should show 27. But doesn't.
        > vgetc() doesn't return ESC key code 27. So I wrote a patch to use
        > vgetc_any() instead of vgetc().
        >
        > https://gist.github.com/mattn/5fd341c1875b34730dfa

        Thanks. Did you check that it still works to obtain a special key?

        --
        If you feel lonely, try schizophrenia.

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ an exciting new programming language -- http://www.Zimbu.org ///
        \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

        --
        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_dev" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
        For more options, visit https://groups.google.com/d/optout.
      • mattn
        ... What special key do you mean? * multi-byte? yes i did * alt+xxx keys? no, getchar(0) doesn t handle alt+xxx before this change Thanks. - Yasuhiro Matsumoto
        Message 3 of 7 , May 14, 2014
        • 0 Attachment
          > Thanks. Did you check that it still works to obtain a special key?

          What special key do you mean?

          * multi-byte? yes i did
          * alt+xxx keys? no, getchar(0) doesn't handle alt+xxx before this change

          Thanks.
          - Yasuhiro Matsumoto

          --
          --
          You received this message from the "vim_dev" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_dev" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
          For more options, visit https://groups.google.com/d/optout.
        • Bram Moolenaar
          ... For example, the cursor-up key . -- hundred-and-one symptoms of being an internet addict: 167. You have more than 200 websites bookmarked. /// Bram
          Message 4 of 7 , May 15, 2014
          • 0 Attachment
            Yasuhiro Matsumoto wrote:

            > > Thanks. Did you check that it still works to obtain a special key?
            >
            > What special key do you mean?
            >
            > * multi-byte? yes i did
            > * alt+xxx keys? no, getchar(0) doesn't handle alt+xxx before this change

            For example, the cursor-up key <Up>.

            --
            hundred-and-one symptoms of being an internet addict:
            167. You have more than 200 websites bookmarked.

            /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
            /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
            \\\ an exciting new programming language -- http://www.Zimbu.org ///
            \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

            --
            --
            You received this message from the "vim_dev" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php

            ---
            You received this message because you are subscribed to the Google Groups "vim_dev" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
            For more options, visit https://groups.google.com/d/optout.
          • mattn
            ... It seems that getchar(0)/getchar(1) doesn t work with cursor-up before this change. -- -- You received this message from the vim_dev maillist. Do not
            Message 5 of 7 , May 15, 2014
            • 0 Attachment
              > > > Thanks. Did you check that it still works to obtain a special key?
              > For example, the cursor-up key <Up>.

              It seems that getchar(0)/getchar(1) doesn't work with cursor-up before this change.

              --
              --
              You received this message from the "vim_dev" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php

              ---
              You received this message because you are subscribed to the Google Groups "vim_dev" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
              For more options, visit https://groups.google.com/d/optout.
            • Tony Mechelynck
              ... I get the following with gvim 7.4.295 (GTK2/GNOME2), testing all three arguments for getchar(): no argument, wait then return the key ... hit key
              Message 6 of 7 , May 15, 2014
              • 0 Attachment
                On 15/05/14 13:15, mattn wrote:
                >>>> Thanks. Did you check that it still works to obtain a special key?
                >> For example, the cursor-up key <Up>.
                >
                > It seems that getchar(0)/getchar(1) doesn't work with cursor-up before this change.
                >
                I get the following with gvim 7.4.295 (GTK2/GNOME2), testing all three
                arguments for getchar():

                no argument, wait then return the key
                :echo getchar()
                hit <Up> key
                <80>ku

                The same, but hit <Esc> instead
                27

                argument 0, return the key if available, else zero
                :let c = 0|while !c|let c = getchar(0)|endwhile|echo c
                hit <Up>
                nothing happens
                hit other cursor-moving keys
                still nothing happens
                hit <Esc>
                27

                argument 1, don't consume the key, return 0 if no key available
                :while !getchar(1)|endwhile|let c = getchar(1)|echo c|let c =
                getchar(0)|echo c
                hit <Up>
                128
                <80>ku

                The same, but hit <Esc> instead
                27
                27

                slight variant on the latter test
                :let c = 0|while !c|let c = getchar(1)|endwhile|echo c|let c =
                getchar(0)|echo c
                hit <Up>
                128
                <80>ku

                The same but hit <Esc>instead
                no visible echo, the command-line is cleared and the cursor returns to
                the main window

                refine the variant
                :let c = 0|while !c|let c = getchar(1)|endwhile|echomsg c|let c =
                getchar(0)|echomsg c
                hit <Esc>
                27
                27


                tl;dr: Works for me in all but one case (multibyte keystroke with
                getchar(0) not preceded by getchar(1) but looped-on instead)


                Best regards,
                Tony.
                --
                hundred-and-one symptoms of being an internet addict:
                115. You are late picking up your kid from school and try to explain
                to the teacher you were stuck in Web traffic.

                --
                --
                You received this message from the "vim_dev" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php

                ---
                You received this message because you are subscribed to the Google Groups "vim_dev" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
                For more options, visit https://groups.google.com/d/optout.
              • Bram Moolenaar
                ... It does work for getchar(0). Put this in a file: sleep 3 echo getchar(0) Source this file and press cursor-up while it s sleeping. -- Microsoft says that
                Message 7 of 7 , May 15, 2014
                • 0 Attachment
                  Yasuhiro Matsumoto wrote:

                  > > > > Thanks. Did you check that it still works to obtain a special
                  > > > > key?
                  > > For example, the cursor-up key <Up>.
                  >
                  > It seems that getchar(0)/getchar(1) doesn't work with cursor-up before
                  > this change.

                  It does work for getchar(0). Put this in a file:

                  sleep 3
                  echo getchar(0)

                  Source this file and press cursor-up while it's sleeping.

                  --
                  Microsoft says that MS-Windows is much better for you than Linux.
                  That's like the Pope saying that catholicism is much better for
                  you than protestantism.

                  /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                  /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
                  \\\ an exciting new programming language -- http://www.Zimbu.org ///
                  \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

                  --
                  --
                  You received this message from the "vim_dev" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php

                  ---
                  You received this message because you are subscribed to the Google Groups "vim_dev" group.
                  To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
                  For more options, visit https://groups.google.com/d/optout.
                Your message has been successfully submitted and would be delivered to recipients shortly.