prompt with timeout

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

prompt with timeout

iler.ml

How can I prompt for "any key" press, with timeout (as a function in
vimscript),
that takes  one argument (timeout in milli), and returns the key
pressed ?
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: prompt with timeout

Tony Mechelynck

On 10/09/08 08:33, Yakov wrote:
> How can I prompt for "any key" press, with timeout (as a function in
> vimscript),
> that takes  one argument (timeout in milli), and returns the key
> pressed ?

If you have a CursorHoldI autocommand, won't the input() function time
out if that autocommand is triggered? I'm not sure since I hardly ever
use that function. It may depend what the autocommand does.


Best regards,
Tony.
--
"You are old," said the youth, "as I mentioned before,
        And have grown most uncommonly fat;
Yet you turned a back-somersault in at the door --
        Pray what is the reason of that?"

"In my youth," said the sage, as he shook his grey locks,
        "I kept all my limbs very supple
By the use of this ointment -- one shilling the box --
        Allow me to sell you a couple?"
                -- Lewis Carrol

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: prompt with timeout

Andy Wokula
In reply to this post by iler.ml

Yakov schrieb:
> How can I prompt for "any key" press, with timeout (as a function in
> vimscript), that takes  one argument (timeout in milli), and returns
> the key pressed ?

You could at least try polling (checking for a key every 50 ms):

" Example:
:let key = GetKeyWithTimeout(3000)|redraw|echo key

func! GetKeyWithTimeout(...)
  let tm = a:0>=1 ? a:1 : &timeoutlen
  echo "Press any key to continue"
  let tmfac = tm / 50
  let key = ""
  while tmfac > 0
      let key = s:getkey()
      if key != ""
          break
      endif
      sleep 50m
      let tmfac -= 1
  endwhile
  return key
endfunc

func! s:getkey()
  if getchar(1)
      let key = getchar()
      if key>0
          let key = nr2char(key)
      endif
  else
      let key = ""
  endif
  return key
endfunc

--
Andy




--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---