def win_handle_is_a_console(handle):
 from ctypes import byref, POINTER, windll, WINFUNCTYPE
 from ctypes.wintypes import BOOL, DWORD, HANDLE
 FILE_TYPE_CHAR = 2
 FILE_TYPE_REMOTE = 32768
 INVALID_HANDLE_VALUE = DWORD((-1)).value
 GetConsoleMode = WINFUNCTYPE(BOOL, HANDLE, POINTER(DWORD))(('GetConsoleMode', windll.kernel32))
 GetFileType = WINFUNCTYPE(DWORD, DWORD)(('GetFileType', windll.kernel32))
 if ((handle == INVALID_HANDLE_VALUE) or (handle is None)):
  return False
 return (((GetFileType(handle) & (~ FILE_TYPE_REMOTE)) == FILE_TYPE_CHAR) and GetConsoleMode(handle, byref(DWORD())))

def win_handle_is_a_console ( handle ) : from ctypes import byref , POINTER , windll , WINFUNCTYPE from ctypes . wintypes import BOOL , DWORD , HANDLE FILE_TYPE_CHAR = 2 FILE_TYPE_REMOTE = 32768 INVALID_HANDLE_VALUE = DWORD ( ( - 1 ) ) . value GetConsoleMode = WINFUNCTYPE ( BOOL , HANDLE , POINTER ( DWORD ) ) ( ( 'GetConsoleMode' , windll . kernel32 ) ) GetFileType = WINFUNCTYPE ( DWORD , DWORD ) ( ( 'GetFileType' , windll . kernel32 ) ) if ( ( handle == INVALID_HANDLE_VALUE ) or ( handle is None ) ) : return False return ( ( ( GetFileType ( handle ) & ( ~ FILE_TYPE_REMOTE ) ) == FILE_TYPE_CHAR ) and GetConsoleMode ( handle , byref ( DWORD ( ) ) ) )
returns true if a windows file handle is a handle to a console .