Josh
Native console access wrapper for Java

com.yifanlu.Josh
Class Josh

java.lang.Object
  extended by com.yifanlu.Josh.JoshBuffer
      extended by com.yifanlu.Josh.Josh
Direct Known Subclasses:
ConsoleBuffer

public class Josh
extends JoshBuffer

Provides native access to the console. The functions defined here are generic for any buffer, for more commands, see out, outBuffer, in, and inBuffer for functions specific to output/input buffers.

Since:
0.1
Version:
1.3, 05/29/10
Author:
Yifan Lu

Field Summary
static JoshInput in
          Contains functions for reading keyboard input from the standard input buffer.
static JoshInBuffer inBuffer
          Contains functions for reading events from the standard input buffer.
static JoshOutput out
          Contains simplified output functions for the standard output buffer.
static JoshOutBuffer outBuffer
          Contains native output functions for the standard output buffer.
static int STD_ERROR_HANDLE
          Used in getStdHandle(int) and setStdHandle(com.yifanlu.Josh.ConsoleBuffer, int).
static int STD_INPUT_HANDLE
          Used in getStdHandle(int) and setStdHandle(com.yifanlu.Josh.ConsoleBuffer, int).
static int STD_OUTPUT_HANDLE
          Used in getStdHandle(int) and setStdHandle(com.yifanlu.Josh.ConsoleBuffer, int).
 
Constructor Summary
Josh()
           
 
Method Summary
static void Beep()
          Generates a single beep of 800Hz for 200 miliseconds.
static void Beep(int frequency, int duration)
          Generates simple tones on the speaker.
static ConsoleHistoryInfo getConsoleHistoryInfo()
          Vista Only: Retrieves the history settings for the calling process's console.
static java.lang.String getConsoleOrginialTitle()
          Vista Only: Retrieves the original title for the current console window.
static ConsoleSelectionInfo getConsoleSelectionInfo()
          XP Only: Retrieves information about the current console selection.
static java.lang.String getConsoleTitle()
          Retrieves the title for the current console window.
static ConsoleHandle getConsoleWindow()
          Retrieves the window handle used by the console associated with the calling process.
static int getNumberOfConsoleMouseButtons()
          Retrieves the number of buttons on the mouse used by the current console.
static ConsoleHandle getStdHandle(int type)
          Retrieves a handle to the specified standard device (standard input, standard output, or standard error).
static boolean isFullScreen()
          XP Only: Sees if the current console window is in fullscreen mode.
static void setConsoleActiveScreenBuffer(ConsoleBuffer screen)
          Sets the specified screen buffer to be the currently displayed console screen buffer.
static void setConsoleHistoryInfo(ConsoleHistoryInfo info)
          Vista Only: Sets the history settings for the calling process's console.
static void setConsoleTitle(java.lang.String title)
          Sets the title for the current console window.
static void setStdHandle(ConsoleBuffer buffer, int forHandle)
          Sets the handle for the specified standard device (standard input, standard output, or standard error).
 
Methods inherited from class com.yifanlu.Josh.JoshBuffer
equals, getHandle, hashCode, setHandle
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STD_INPUT_HANDLE

public static final int STD_INPUT_HANDLE
Used in getStdHandle(int) and setStdHandle(com.yifanlu.Josh.ConsoleBuffer, int). Different handles to get/set.

See Also:
Constant Field Values

STD_OUTPUT_HANDLE

public static final int STD_OUTPUT_HANDLE
Used in getStdHandle(int) and setStdHandle(com.yifanlu.Josh.ConsoleBuffer, int). Different handles to get/set.

See Also:
Constant Field Values

STD_ERROR_HANDLE

public static final int STD_ERROR_HANDLE
Used in getStdHandle(int) and setStdHandle(com.yifanlu.Josh.ConsoleBuffer, int). Different handles to get/set.

See Also:
Constant Field Values

out

public static final JoshOutput out
Contains simplified output functions for the standard output buffer.


outBuffer

public static final JoshOutBuffer outBuffer
Contains native output functions for the standard output buffer.


in

public static final JoshInput in
Contains functions for reading keyboard input from the standard input buffer.


inBuffer

public static final JoshInBuffer inBuffer
Contains functions for reading events from the standard input buffer.

Constructor Detail

Josh

public Josh()
Method Detail

Beep

public static void Beep()
Generates a single beep of 800Hz for 200 miliseconds.


Beep

public static void Beep(int frequency,
                        int duration)
Generates simple tones on the speaker. The function is synchronous; it performs an alertable wait and does not return control to its caller until the sound finishes.

Parameters:
frequency - The frequency of the sound, in hertz. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).
duration - The duration of the sound, in milliseconds.

setConsoleActiveScreenBuffer

public static void setConsoleActiveScreenBuffer(ConsoleBuffer screen)
Sets the specified screen buffer to be the currently displayed console screen buffer.

Parameters:
screen - A ConsoleBuffer that should be displayed.
See Also:
Windows' SetConsoleActiveScreenBuffer function

getConsoleTitle

public static java.lang.String getConsoleTitle()
Retrieves the title for the current console window.

Returns:
The current title.
See Also:
Windows' GetConsoleTitle function

setConsoleTitle

public static void setConsoleTitle(java.lang.String title)
Sets the title for the current console window.

Parameters:
title - The string to be displayed in the title bar of the console window.
See Also:
Windows' SetConsoleTitle function

getConsoleOrginialTitle

public static java.lang.String getConsoleOrginialTitle()
                                                throws OSNotSupportedException
Vista Only: Retrieves the original title for the current console window. This method only works with Windows Vista or higher.
This is the title of the Window when the application first launched.

Returns:
The original title.
Throws:
OSNotSupportedException - If the current OS is not Vista or higher.
See Also:
Windows' GetConsoleOriginalTitle function

getConsoleHistoryInfo

public static ConsoleHistoryInfo getConsoleHistoryInfo()
                                                throws OSNotSupportedException
Vista Only: Retrieves the history settings for the calling process's console. This method only works with Windows Vista or higher.

Returns:
The history settings for the calling process's console.
Throws:
OSNotSupportedException - If the current OS is not Vista or higher.
See Also:
Windows' GetConsoleHistoryInfo function

setConsoleHistoryInfo

public static void setConsoleHistoryInfo(ConsoleHistoryInfo info)
                                  throws OSNotSupportedException
Vista Only: Sets the history settings for the calling process's console. This method only works with Windows Vista or higher.

Parameters:
info - The history settings for the calling process's console.
Throws:
OSNotSupportedException - If the current OS is not Vista or higher.
See Also:
Windows' SetConsoleHistoryInfo function

getConsoleSelectionInfo

public static ConsoleSelectionInfo getConsoleSelectionInfo()
                                                    throws OSNotSupportedException
XP Only: Retrieves information about the current console selection. This method only works with Windows XP or higher.

Returns:
The selection information.
Throws:
OSNotSupportedException - If the current OS is not XP or higher.
See Also:
Windows' GetConsoleSelectionInfo function

getConsoleWindow

public static ConsoleHandle getConsoleWindow()
Retrieves the window handle used by the console associated with the calling process.

Returns:
The window used by the console associated with the calling process.
See Also:
Windows' GetConsoleWindow function

getNumberOfConsoleMouseButtons

public static int getNumberOfConsoleMouseButtons()
Retrieves the number of buttons on the mouse used by the current console.

Returns:
The number of mouse buttons.
See Also:
Windows' GetNumberOfConsoleMouseButtons function

getStdHandle

public static ConsoleHandle getStdHandle(int type)
Retrieves a handle to the specified standard device (standard input, standard output, or standard error).

Parameters:
type - The standard device which is a constant defined in this class.
Returns:
The specified device, or a redirected handle set by a previous call to SetStdHandle. The handle has GENERIC_READ and GENERIC_WRITE access rights, unless the application has used SetStdHandle to set a standard handle with lesser access.
See Also:
Windows' GetStdHandle function

setStdHandle

public static void setStdHandle(ConsoleBuffer buffer,
                                int forHandle)
Sets the handle for the specified standard device (standard input, standard output, or standard error).

Parameters:
buffer - What to set as the standard handle.
forHandle - The standard device which is a constant defined in this class.
See Also:
Windows' SetStdHandle function

isFullScreen

public static boolean isFullScreen()
                            throws OSNotSupportedException
XP Only: Sees if the current console window is in fullscreen mode. This method only works with Windows XP or higher.

Returns:
True if the console is in fullscreen.
Throws:
OSNotSupportedException - If the current OS is not XP or higher.
See Also:
Windows' GetConsoleDisplayMode function

Copyright © 2010 Yifan Lu