本文目錄一覽:
- 1、請教關於用python編寫屏幕取詞的程序問題
- 2、怎麼用python實現電腦cpu溫度監控,最好有代碼,windows平台,求大神
- 3、python編程,我方和敵,開始時血量(HP)都是300,輪流攻擊,造成傷害1-100之間的隨機數,一方HP空結束?
請教關於用python編寫屏幕取詞的程序問題
1、屏幕取詞技術實現原理與關鍵源碼—-
Ubuntu 下可以監視 gtk.Clipboard 來獲取當前選中文字和位置。
我以前嘗試過定時抓取鼠標附近圖像做 OCR 來取詞,
改成快捷鍵取詞會省一點。
直接獲得文字的懸停取詞比較麻煩。
網頁、XUL 應用程序可以有鼠標懸停事件。
X11 自己沒有, 不過以前流行中文平台、中文外掛時候 TurboLinux 的中文 X-window 被修改為集成鼠標懸停取詞翻譯。
Gtk 程序也許你可以在 ATK 層入手,自己改 ATK 和用 LD_LIBRARY_PATH。
windows下很不好做。
普遍用的是HOOK API的方法。
可以參考stardict的取詞模塊。
不過我感覺stardict的取詞模塊也不是太好用(沒金山詞霸的好用),感覺有bug。
似乎以前某版本的金山詞霸可以翻譯圖片中的文字,就是用 OCR
再,金山似乎出過 Linux Qt3 版本,找 Zoomq 幾位在金山的老大索取源碼看看吧
嗯, 金山詞霸確實出過 Linux 版本,
是基於 wine 的,不是原生的 Linux 版本…
linux下就不知道,windows下,應該是做一個api hook,鉤住TextOut,DrawText和DrawTextEx。
要取詞的時候給鼠標所在的窗口發一個WM_PAINT消息,讓窗口重繪。
當窗口調用TextOut, DrawText或是DrawTextEx進行重繪的時候,你就可以根據傳入的參數知道
窗口想在鼠標下畫什麼東西了。
怎麼用python實現電腦cpu溫度監控,最好有代碼,windows平台,求大神
from __future__ import division
import os
from collections import namedtuple
_nt_cpu_temp = namedtuple(‘cputemp’, ‘name temp max critical’)
def get_cpu_temp(fahrenheit=False):
“””Return temperatures expressed in Celsius for each physical CPU
installed on the system as a list of namedtuples as in:
get_cpu_temp()
[cputemp(name=’atk0110′, temp=32.0, max=60.0, critical=95.0)]
“””
#
cat = lambda file: open(file, ‘r’).read().strip()
base = ‘/sys/class/hwmon/’
ls = sorted(os.listdir(base))
assert ls, “%r is empty” % base
ret = []
for hwmon in ls:
hwmon = os.path.join(base, hwmon)
label = cat(os.path.join(hwmon, ‘temp1_label’))
assert ‘cpu temp’ in label.lower(), label
name = cat(os.path.join(hwmon, ‘name’))
temp = int(cat(os.path.join(hwmon, ‘temp1_input’))) / 1000
max_ = int(cat(os.path.join(hwmon, ‘temp1_max’))) / 1000
crit = int(cat(os.path.join(hwmon, ‘temp1_crit’))) / 1000
digits = (temp, max_, crit)
if fahrenheit:
digits = [(x * 1.8) + 32 for x in digits]
ret.append(_nt_cpu_temp(name, *digits))
return ret
python編程,我方和敵,開始時血量(HP)都是300,輪流攻擊,造成傷害1-100之間的隨機數,一方HP空結束?
代碼如下(縮進請參考截圖):
from random import randint
me_hp = 300
enemy_hp = 300
while True:
m_hurt = randint(1, 100)
if enemy_hp – m_hurt 0:
enemy_hp -= m_hurt
print(‘造成 {:3} 點傷害,敵方HP為: {:3}’.format(m_hurt, enemy_hp))
else:
print(‘造成 {:3} 點傷害,Victory!’.format(m_hurt))
break
e_hurt = randint(1, 100)
if me_hp – e_hurt 0:
me_hp -= e_hurt
print(‘受到 {:3} 點傷害,當前HP為: {:3}’.format(e_hurt, me_hp))
else:
print(‘受到 {:3} 點傷害,Defeated!’.format(e_hurt))
break
輸出如下:
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/305196.html