#author("2020-04-10T23:25:18+00:00","default:mizutu","mizutu") [[私的AI研究会]] > AIbot Proj.1 * AI Robot Project &color(green){~編集中~}; [#f0f94bee] #contents ** aibot.py [#sf49b649] ** sibotrm.py [#jf4cd9bc] ** Pythonでリアルタイムにキーボード入力を処理する方法 [#zecc8b23] > Pythonではreadcharというライブラリを使う。 - インストール $ pip install readchar - サンプリプログラム #!/usr/bin/env python import readchar import sys while 1: kb = readchar.readchar() # sys.stdout.write(kb) print(ord(kb)) if kb == 'q': print("") break - IDE環境では実行できない Python error: (25, 'Inappropriate ioctl for device') * 参考資料 [#c99761a3] - [[Python: input from Keyboard without Enter>+http://web.sfc.keio.ac.jp/~yama/nos/archives/comp/soft/5326]] -[[pythonでコンソールから1文字入力>+https://emotionexplorer.blog.fc2.com/blog-entry-126.html]] - [[python3にもkbhit()とgetch()が欲しい>+https://westgate-lab.hatenablog.com/entry/2019/12/28/123451]] - [[【Python】文字列と数値(asciiコード)の変換まとめ>+https://qiita.com/ell/items/6eb48e934a147898d823]] - [[Python Snippets>+https://python.civic-apps.com/char-ord/]] - [[Pythonでコマンドライン引数を受け取る>+https://qiita.com/taashi/items/07bf75201a074e208ae5]] - [[ASCIIコード表>+http://www9.plala.or.jp/sgwr-t/c_sub/ascii.html]] #br