Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: eryksun Newsgroups: comp.lang.python Subject: Re: non-blocking getkey? Date: Fri, 20 Nov 2015 02:43:13 -0600 Lines: 43 Message-ID: References: <564DF94E.8020302@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de zvVKgHusMPEsRtFIpixaCgcYhMqwmSM0Jc703MixDghw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'win32': 0.03; 'root': 0.04; 'importerror:': 0.05; 'sys': 0.05; '__name__': 0.07; 'filename': 0.07; 'sys.platform': 0.07; 'url:msdn': 0.07; 'api': 0.09; "%s'": 0.09; '[1]:': 0.09; '[2]:': 0.09; 'filename)': 0.09; 'def': 0.13; 'thu,': 0.15; "'__main__':": 0.16; "'win32':": 0.16; '[2].': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:non': 0.16; 'wrote:': 0.16; 'skip:u 30': 0.18; 'try:': 0.18; 'input': 0.18; 'windows': 0.20; '2015': 0.20; 'ctypes': 0.22; 'tkinter': 0.22; 'am,': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'switch': 0.27; 'message-id:@mail.gmail.com': 0.27; 'windows,': 0.29; 'window': 0.30; '[1]': 0.32; 'michael': 0.33; 'except': 0.34; 'received:google.com': 0.35; 'false': 0.35; 'nov': 0.35; 'received:209.85': 0.36; 'possible': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'skip:o 20': 0.38; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'url:en-us': 0.72 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=pnZxDSPKosR1db25V0wLJNtQHm5Xd5pi1wMOm9Ycfr8=; b=NsL5ub7Yw2kzOjlyWJkyVcCDOVn2TR0WjBOBkgJxjkYS7cMLKo3YC7F4BmlSPH9/72 rpBj2C2AaLlHNopkxqK5/Bx4nOOEJLWZbeIjPfwGAxRh/dd2JdVDF8EEXi6r2RKM2/xv nX/YmME9wzApby3CXeHqgZMWDI/nJquUtAPEM515Ue2oaSatvaaaQGsZp1x0kceW9y+j rCjKMBokeut1TBDETPD+KdiTf8N8E36kOrW0FzjsKvFn1RIJyc/Hiqme+TH2g9De7ycF wtvG3WyYqmWFJUmiPYWepjYrTVrDu6JyyTKAdbrWVPrXWNj+EtcsOxCTDmjKgDZCktRd Cqxw== X-Received: by 10.107.137.226 with SMTP id t95mr12535890ioi.188.1448009032809; Fri, 20 Nov 2015 00:43:52 -0800 (PST) In-Reply-To: <564DF94E.8020302@gmail.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99133 On Thu, Nov 19, 2015 at 10:31 AM, Michael Torrie wrote: > One windows it might be possible to use the win32 api to enumerate the > windows, find your console window and switch to it. You can call GetConsoleWindow [1] and then SetForegroundWindow [2]. import os import sys try: import tkinter from tkinter import filedialog except ImportError: import Tkinter as tkinter import tkFileDialog as filedialog input = raw_input if sys.platform == 'win32': import ctypes kernel32 = ctypes.WinDLL('kernel32') user32 = ctypes.WinDLL('user32') def setfgwin(): hcon = kernel32.GetConsoleWindow() if hcon and user32.SetForegroundWindow(hcon): return True return False def get_filename(): filename = filedialog.askopenfilename() setfgwin() return os.path.normpath(filename) if __name__ == '__main__': root = tkinter.Tk() root.withdraw() filename = get_filename() print('filename: %s' % filename) input('press enter...') [1]: https://msdn.microsoft.com/en-us/library/ms683175 [2]: https://msdn.microsoft.com/en-us/library/ms633539