写経により邪念を滅却し、功徳を積もう
写経は、一字書くたびに一体の仏像を彫ることと同じである、
と言われております。
仏像彫る人が可哀そうじゃね?
昨今の現代社会のストレスに耐え兼ね
私も写経によって心を落ち着かせ、
極楽浄土への功徳を積みたいと思うようになりました。
写経とは?
写経(しゃきょう)とは、仏教において経典を書写すること。
現代の日本で写経と言えば、『般若心経』の書写を指すことが多い。
(参考:Wikipedia )
効率的に写経するために
俗世の欲にまみれたエンジニアのみなさまは
常に効率化を考えてしまいがちですね。業(ごう)が深いことです。
効率化の例として、チベット仏教には
マニ車
というものがございまして、
1回転させると1回お経を読んだのと同じだけ、
徳を積んだことになるそうです。
これがなかなかの優れものでして、
水車マニ車、風車マニ車、ソーラーマニ車、など
**「オートで功徳を積める」**ものが多数出現しております。
ハンドスピーナーマニ車まである模様
しかし、マニ車ではちょっと頑張った感がありません。
そこで今回、「写経感を損なわないようにしながらも」
「オートで写経できる仕組み」をPythonで作ってみたのでございます。
出来たもの
こちらのgifをご覧くださいませ。
最終的に動作コード含めて作り方を全てご提示いたします。
重要な方針=真心をこめた一打鍵
幸いなことに、「写経」については、
その手段/フォーマット(使う道具)は問われないと聞いております。
(宗派によるそうです)
そこで、筆⇒キーボード入力、紙⇒電子化、までは許されると仮定できます。
- ログでバーッと出すような仕組み ⇒ NG
- キーボード入力の自動化 ⇒ OK
と仮定しました。
仏様の像を彫るような気持ちで真心をこめて、一打鍵ずつ、
ha nn nya si nn gyo u
と入力していけば良いわけですね。
自動化までの道のり
キーボード入力の自動化= pyautogui
pip install pyautogui
以下のようにして、打鍵の自動化ができます。
import pyautogui
#エンターキーを2回押す
pyautogui.press('enter', presses=2)
#コントロール+V
pyautogui.hotkey('ctrl', 'v')
#任意の文字列のタイピング
pyautogui.typewrite("hannya")
他の使い方詳細は、下記の素晴らしい記事をご参照くださいませ。
https://qiita.com/hirohiro77/items/78e26a59c2e45a0fe4e3
自動化の難題=日本語非対応
当初は、以下のような感じかなーと思っておりました。
pyautogui.typewrite("般若心経")
が、日本語には対応していなかったのです!
そこで ローマ字 + 変換キー にしてみたのですが・・・
#ローマ字で入力させて
pyautogui.typewrite("hannnyasinngyou")
#変換すればよいのではないか?
pyautogui.press('space"', presses=1)
これだと、日本語入力をONにしていれば入力は出来るのですが、
重要な問題:
般若心経の漢字はIMEでほとんどまともに出てこない
変換が効かないんですよね、仮に出てきたとしても、
何番目にその正しい対象があるのか取得は難しいです。
漢字はクリップボードコピペ=pyperclip
そこで、漢字はクリップボード経由で
事前に登録 ⇒ ctrl+V
という形で入力することを思いつきました。
pyperclip を使えばクリップボードに介入できます。
pip install pyperclip
以下のようにして、クリップボード操作ができます。
import pyautogui
import pyperclip
#クリップボードに登録
pyperclip.copy(”般若心経”)
#コピペ
pyautogui.hotkey('ctrl', 'v')
しかし、もし全てctrl+Vだけで写経していたら、
当初の目的であった「写経感」が失われてしまい、
ログを出しているのと同じような感じになってしまいます。
そこで、きちんとキーボード入力を行いつつ、
出力を正しい漢字にするという融合が必要になってきます。
楽して写経しようなどという考えは甘いのです。
写経感の工夫ポイント=ESCキー
pyautogui によってキー入力を行いつつ、
その変換の代わりに、「ESCキー」を連打することで、
入力した内容を消去し、
消去した瞬間にctrl+V作戦を行うことで、
IMEの変換っぽく見せることができる
という画期的な新技術を編み出しました。
コードの詳細は最後の全行コード内でご確認ください。
出来た全部のコード
さあこのコードで、みなさんもオートで功徳を積んでみてください。
部屋を暗くして、誰も居ない部屋で
繰り返し回数を多くして実行すると雰囲気が出てオススメです!
環境に応じて多少改変してお使いください。
#!usr/bin/python
# -*- coding: UTF-8 -*-
##PyAutoGUIのモジュール
#pip install pyautogui
import pyautogui
#クリップボードコピペ用
#pip install pyperclip
import pyperclip
import sys
import time
def GijiHenkan(kanji, roumaji, sleeptime):
#roumaji文字列をタイプする(※全角モード前提)
#pyautogui.typewrite(roumaji)
#↑不自然に早いので不採用
#全部の文字を一文字ずつ打つ
for char in roumaji:
pyautogui.press(char, presses=1)
time.sleep(sleeptime)
#変換前にひとこきゅう
time.sleep(sleeptime)
#クリップボードに漢字をコピーしておく
pyperclip.copy(kanji)
#消去した瞬間にクリップボードから文字をコピペ
#消去については環境ごとに異なる可能性があるが、
#escの2回押しにしておく。
pyautogui.press('esc', presses=2)
#コピペ
pyautogui.hotkey('ctrl', 'v')
#ひとこきゅう
time.sleep(sleeptime)
return 0
def Kaigyou(sleeptime):
pyautogui.press('enter', presses=1)
time.sleep(sleeptime)
return 0
def DoSyakyou(sleeptime,kaigyousleeptime):
GijiHenkan("摩","ma",sleeptime)
GijiHenkan("訶","ka",sleeptime)
GijiHenkan("般","hann",sleeptime)
GijiHenkan("若","nya",sleeptime)
GijiHenkan("波","ha",sleeptime)
GijiHenkan("羅","ra",sleeptime)
GijiHenkan("蜜","mi",sleeptime)
GijiHenkan("多","ta",sleeptime)
GijiHenkan("心","sinn",sleeptime)
GijiHenkan("経","gyou",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("観","kann",sleeptime)
GijiHenkan("自","ji",sleeptime)
GijiHenkan("在","zai",sleeptime)
GijiHenkan("菩","bo",sleeptime)
GijiHenkan("薩","satu",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("行","gyou",sleeptime)
GijiHenkan("深","jinn",sleeptime)
GijiHenkan("般","hann",sleeptime)
GijiHenkan("若","nya",sleeptime)
GijiHenkan("波","ha",sleeptime)
GijiHenkan("羅","ra",sleeptime)
GijiHenkan("蜜","mixtu",sleeptime)
GijiHenkan("多","ta",sleeptime)
GijiHenkan("時","ji",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("照","syou",sleeptime)
GijiHenkan("見","ken",sleeptime)
GijiHenkan("五","go",sleeptime)
GijiHenkan("蘊","unn",sleeptime)
GijiHenkan("皆","kai",sleeptime)
GijiHenkan("空","kuu",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("度","do",sleeptime)
GijiHenkan("一","ixtu",sleeptime)
GijiHenkan("切","sai",sleeptime)
GijiHenkan("苦","ku",sleeptime)
GijiHenkan("厄","yaku",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("舍","sya",sleeptime)
GijiHenkan("利","ri",sleeptime)
GijiHenkan("子","si",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("色","siki",sleeptime)
GijiHenkan("不","hu",sleeptime)
GijiHenkan("異","i",sleeptime)
GijiHenkan("空","kuu",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("空","kuu",sleeptime)
GijiHenkan("不","hu",sleeptime)
GijiHenkan("異","i",sleeptime)
GijiHenkan("色","siki",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("色","siki",sleeptime)
GijiHenkan("即","soku",sleeptime)
GijiHenkan("是","ze",sleeptime)
GijiHenkan("空","kuu",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("空","kuu",sleeptime)
GijiHenkan("即","soku",sleeptime)
GijiHenkan("是","ze",sleeptime)
GijiHenkan("色","siki",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("受","jyu",sleeptime)
GijiHenkan("想","sou",sleeptime)
GijiHenkan("行","gyou",sleeptime)
GijiHenkan("識","siki",sleeptime)
GijiHenkan("亦","yaku",sleeptime)
GijiHenkan("復","bu",sleeptime)
GijiHenkan("如","nyo",sleeptime)
GijiHenkan("是","ze",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("舍","sya",sleeptime)
GijiHenkan("利","ri",sleeptime)
GijiHenkan("子","si",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("是","ze",sleeptime)
GijiHenkan("諸","syo",sleeptime)
GijiHenkan("法","hou",sleeptime)
GijiHenkan("空","kuu",sleeptime)
GijiHenkan("相","sou",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("不","hu",sleeptime)
GijiHenkan("生","syou",sleeptime)
GijiHenkan("不","hu",sleeptime)
GijiHenkan("滅","metu",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("不","hu",sleeptime)
GijiHenkan("垢","ku",sleeptime)
GijiHenkan("不","hu",sleeptime)
GijiHenkan("浄","jyou",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("不","hu",sleeptime)
GijiHenkan("増","zou",sleeptime)
GijiHenkan("不","hu",sleeptime)
GijiHenkan("減","genn",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("是","ze",sleeptime)
GijiHenkan("故","ko",sleeptime)
GijiHenkan("空","kuu",sleeptime)
GijiHenkan("中","tyuu",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("色","siki",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("受","jyu",sleeptime)
GijiHenkan("想","sou",sleeptime)
GijiHenkan("行","gyou",sleeptime)
GijiHenkan("識","siki",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("眼","genn",sleeptime)
GijiHenkan("耳","ni",sleeptime)
GijiHenkan("鼻","bi",sleeptime)
GijiHenkan("舌","zextu",sleeptime)
GijiHenkan("身","sinn",sleeptime)
GijiHenkan("意","i",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("色","siki",sleeptime)
GijiHenkan("声","syou",sleeptime)
GijiHenkan("香","kou",sleeptime)
GijiHenkan("味","mi",sleeptime)
GijiHenkan("触","soku",sleeptime)
GijiHenkan("法","hou",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("眼","genn",sleeptime)
GijiHenkan("界","kai",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("乃","nai",sleeptime)
GijiHenkan("至","si",sleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("意","i",sleeptime)
GijiHenkan("識","siki",sleeptime)
GijiHenkan("界","kai",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("明","myou",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("亦","yaku",sleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("明","myou",sleeptime)
GijiHenkan("尽","jinn",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("乃","nai",sleeptime)
GijiHenkan("至","si",sleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("老","rou",sleeptime)
GijiHenkan("死","si",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("亦","yaku",sleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("老","rou",sleeptime)
GijiHenkan("死","si",sleeptime)
GijiHenkan("尽","jinn",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("苦","ku",sleeptime)
GijiHenkan("集","syuu",sleeptime)
GijiHenkan("滅","metu",sleeptime)
GijiHenkan("道","dou",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("智","ti",sleeptime)
GijiHenkan("亦","yaku",sleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("得","toku",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("以","i",sleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("所","syo",sleeptime)
GijiHenkan("得","toku",sleeptime)
GijiHenkan("故","kou",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("菩","bo",sleeptime)
GijiHenkan("提","dai",sleeptime)
GijiHenkan("薩","saxtu",sleeptime)
GijiHenkan("埵","ta",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("依","e",sleeptime)
GijiHenkan("般","hann",sleeptime)
GijiHenkan("若","nya",sleeptime)
GijiHenkan("波","ha",sleeptime)
GijiHenkan("羅","ra",sleeptime)
GijiHenkan("蜜","mixtu",sleeptime)
GijiHenkan("多","ta",sleeptime)
GijiHenkan("故","ko",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("心","sinn",sleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("罣","kei",sleeptime)
GijiHenkan("礙","ge",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("罣","kei",sleeptime)
GijiHenkan("礙","ge",sleeptime)
GijiHenkan("故","ko",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("有","u",sleeptime)
GijiHenkan("恐","ku",sleeptime)
GijiHenkan("怖","hu",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("遠","onn",sleeptime)
GijiHenkan("離","ri",sleeptime)
GijiHenkan("一","ixtu",sleeptime)
GijiHenkan("切","sai",sleeptime)
GijiHenkan("顛","tenn",sleeptime)
GijiHenkan("倒","dou",sleeptime)
GijiHenkan("夢","mu",sleeptime)
GijiHenkan("想","sou",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("究","ku",sleeptime)
GijiHenkan("竟","kyou",sleeptime)
GijiHenkan("涅","ne",sleeptime)
GijiHenkan("槃","hann",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("三","sann",sleeptime)
GijiHenkan("世","ze",sleeptime)
GijiHenkan("諸","syo",sleeptime)
GijiHenkan("仏","butu",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("依","e",sleeptime)
GijiHenkan("般","hann",sleeptime)
GijiHenkan("若","nya",sleeptime)
GijiHenkan("波","ha",sleeptime)
GijiHenkan("羅","ra",sleeptime)
GijiHenkan("蜜","mixtu",sleeptime)
GijiHenkan("多","ta",sleeptime)
GijiHenkan("故","ko",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("得","toku",sleeptime)
GijiHenkan("阿","a",sleeptime)
GijiHenkan("耨","noku",sleeptime)
GijiHenkan("多","ta",sleeptime)
GijiHenkan("羅","ra",sleeptime)
GijiHenkan("三","sann",sleeptime)
GijiHenkan("藐","myaku",sleeptime)
GijiHenkan("三","sann",sleeptime)
GijiHenkan("菩","bo",sleeptime)
GijiHenkan("提","dai",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("故","ko",sleeptime)
GijiHenkan("知","ti",sleeptime)
GijiHenkan("般","hann",sleeptime)
GijiHenkan("若","nya",sleeptime)
GijiHenkan("波","ha",sleeptime)
GijiHenkan("羅","ra",sleeptime)
GijiHenkan("蜜","mixtu",sleeptime)
GijiHenkan("多","ta",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("是","ze",sleeptime)
GijiHenkan("大","dai",sleeptime)
GijiHenkan("神","jinn",sleeptime)
GijiHenkan("呪","syu",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("是","ze",sleeptime)
GijiHenkan("大","dai",sleeptime)
GijiHenkan("明","myou",sleeptime)
GijiHenkan("呪","syu",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("是","ze",sleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("上","jyou",sleeptime)
GijiHenkan("呪","syu",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("是","ze",sleeptime)
GijiHenkan("無","mu",sleeptime)
GijiHenkan("等","tou",sleeptime)
GijiHenkan("等","dou",sleeptime)
GijiHenkan("呪","syu",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("能","nou",sleeptime)
GijiHenkan("除","jyo",sleeptime)
GijiHenkan("一","ixtu",sleeptime)
GijiHenkan("切","sai",sleeptime)
GijiHenkan("苦","ku",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("真","sinn",sleeptime)
GijiHenkan("実","jitu",sleeptime)
GijiHenkan("不","hu",sleeptime)
GijiHenkan("虚","ko",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("故","ko",sleeptime)
GijiHenkan("説","setu",sleeptime)
GijiHenkan("般","hann",sleeptime)
GijiHenkan("若","nya",sleeptime)
GijiHenkan("波","ha",sleeptime)
GijiHenkan("羅","ra",sleeptime)
GijiHenkan("蜜","mixtu",sleeptime)
GijiHenkan("多","ta",sleeptime)
GijiHenkan("呪","syu",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("即","soku",sleeptime)
GijiHenkan("説","setu",sleeptime)
GijiHenkan("呪","syu",sleeptime)
GijiHenkan("曰","watu",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("羯","gya",sleeptime)
GijiHenkan("諦","tei",sleeptime)
GijiHenkan("羯","gya",sleeptime)
GijiHenkan("諦","tei",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("波","ha",sleeptime)
GijiHenkan("羅","ra",sleeptime)
GijiHenkan("羯","gya",sleeptime)
GijiHenkan("諦","tei",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("波","ha",sleeptime)
GijiHenkan("羅","ra",sleeptime)
GijiHenkan("僧","sou",sleeptime)
GijiHenkan("羯","gya",sleeptime)
GijiHenkan("諦","tei",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("菩","bo",sleeptime)
GijiHenkan("提","ji",sleeptime)
GijiHenkan("薩","so",sleeptime)
GijiHenkan("婆","wa",sleeptime)
GijiHenkan("訶","ka",sleeptime)
Kaigyou(kaigyousleeptime)
GijiHenkan("般","hann",sleeptime)
GijiHenkan("若","nya",sleeptime)
GijiHenkan("心","sinn",sleeptime)
GijiHenkan("経","gyou",sleeptime)
Kaigyou(kaigyousleeptime)
Kaigyou(kaigyousleeptime)
Kaigyou(kaigyousleeptime)
return 0
#以下、メインルーチン
if __name__ == "__main__":
#実行前の待機(秒)
print("5秒後に写経が始まります。")
print("心を静かにして")
print("テキストエディタを開いて、")
print("日本語入力モードにしておきましょう。")
time.sleep(5)
sleeptime = 0.0015
kaigyousleeptime = 0.02
#写経開始
#強制終了(ctrl+c)するときにキーボード入力が継続されてしまうので
#実行する際には注意。
#繰り返し回数は最初は1回だけなどにしておいた方がよい
for var in range(0, 3):
DoSyakyou(sleeptime,kaigyousleeptime)
print("おつとめおつかれさまでした。")
sys.exit()
あとがき
写経を(自動で)していると、
心が洗われるような感じがいたします。
特にエンジニアのみなさまにおかれましては、
「コンピュータが何か頑張っている感の様子を見ること」
だけでも心が洗われる、という統計結果が出ております。
(エンジニア3名に聞いてみた7つの心理的安全性 ~~民明書房~~)
プログラム起動中は他の作業は一切出来ない「禅仕様」ですので、
ぜひみなさまも、
お忙しいなかの日常にも写経というオアシスを
取り込んでみてはいかがでしょうか?
また、日ごろお世話になっているみなさまへの感謝を込めて
1いいねごとに1回、
心を込めた自動写経を代行させていただきます。
ぽちっと押すだけで功徳を積める、Qiita史上最高に徳の高い記事です。
写経だけではなく読経したい方へのオススメ
以前ご紹介させていただいた、日本一の速読アプリにも、
般若心経を速読or念じられるモードを搭載しております。
訓練不要で誰でも速読!日本一の速読アプリ「瞬間速読」の個人開発物語(25万DL)
よろしければこちらもぜひご参照くださいませ。
ツッコミ
って、プログラムの「写経」じゃなくて、
ホンモノの「写経」の話だったんかーい!!!!
誰かの心の声が聞こえたような気がいたします。
悟りをひらいた仏様は「六神通」という超能力をお持ちで、
その一つ「他神通」では「他人の心を知る事ができる能力」があるそうですが、
私も本記事で沢山の功徳を積んだことで、
そのひとつに目覚めつつあるのかもしれません。
今回は、このツッコミをここまでひっぱって書くことと、
途中のお経データ入力が一番大変でした。
以上です。
後日追記:本稿を技術的にさらに発展させた記事を書いてみたのでございます。
何もない所から一瞬で、自然言語処理と係り受け解析をライブコーディングする手品を、LTでやってみた話
https://qiita.com/youwht/items/b047225a6fc356fd56ee