Keyboard input/Keypress check: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|Python}}: someone should test, if still working also in windows environment and prior implementation 'char.decode('utf-8')' throws error when using german 'Ä,Ö,Ü,ä,ö,ü') |
||
Line 443: | Line 443: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
<lang python>#!/usr/bin/env python |
<lang python>#!/usr/bin/env python |
||
# -*- coding: utf-8 -*- |
|||
from __future__ import absolute_import, division, unicode_literals, print_function |
|||
import __future__ |
|||
import sys |
import sys |
||
if sys.version_info.major < 3: |
if sys.version_info.major < 3: |
||
Line 466: | Line 467: | ||
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) |
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) |
||
return ch |
return ch |
||
⚫ | |||
def keypress(): |
def keypress(): |
||
Line 473: | Line 472: | ||
char = getch() |
char = getch() |
||
def main(): |
|||
⚫ | |||
global char |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
_thread.start_new_thread(keypress, ()) |
|||
if char == 'q' or char == '\x1b': # x1b is ESC |
|||
exit() |
|||
char = None |
|||
⚫ | |||
⚫ | |||
if __name__ == "__main__": |
|||
⚫ | |||
main() |
|||
⚫ | |||
⚫ | |||
break |
|||
⚫ | |||
⚫ | |||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |