Module: TTY::Reader::WinAPI
- Includes:
- Fiddle
- Defined in:
- lib/tty/reader/win_api.rb
Constant Summary collapse
- Handle =
RUBY_VERSION >= "2.0.0" ? Fiddle::Handle : DL::Handle
- CRT_HANDLE =
Handle.new("msvcrt") rescue Handle.new("crtdll")
Class Method Summary collapse
-
.getch ⇒ String
Get a character from the console without echo.
-
.getche ⇒ String
Gets a character from the console with echo.
-
.kbhit ⇒ Integer
Check the console for recent keystroke.
Class Method Details
.getch ⇒ String
Get a character from the console without echo.
21 22 23 24 |
# File 'lib/tty/reader/win_api.rb', line 21 def getch @@getch ||= Fiddle::Function.new(CRT_HANDLE["_getch"], [], TYPE_INT) @@getch.call end |
.getche ⇒ String
Gets a character from the console with echo.
33 34 35 36 |
# File 'lib/tty/reader/win_api.rb', line 33 def getche @@getche ||= Fiddle::Function.new(CRT_HANDLE["_getche"], [], TYPE_INT) @@getche.call end |
.kbhit ⇒ Integer
Check the console for recent keystroke. If the function returns a nonzero value, a keystroke is waiting in the buffer.
47 48 49 50 |
# File 'lib/tty/reader/win_api.rb', line 47 def kbhit @@kbhit ||= Fiddle::Function.new(CRT_HANDLE["_kbhit"], [], TYPE_INT) @@kbhit.call end |