2024年2月27日 星期二

打字練習程式例

 namespace WinFormsApp7

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        int wctr = 0;

        int intervalCtr = 0;

        string str1 = "向晚意不適,驅車登古原,夕陽無限好,只是近黃昏";

        private void Form1_Load(object sender, EventArgs e)

        {

            timer1.Enabled = true;

            timer1.Interval = 100;

            label1.Text = str1.Substring(0, 1);

            label2.Text = "";

            Text = "打字練習";

            label3.Text = "字數統計:" + wctr.ToString();

        }

        int tc = 0;

        private void timer1_Tick(object sender, EventArgs e)

        {

            label1.Top += 10;

            intervalCtr++;

            if (label1.Top > label2.Top)

            {

                label2.Text += label1.Text;

                tc++;

                tc = tc % str1.Length;

                label1.Text = str1[tc].ToString();

                label1.Top = 27;

            }

            label4.Text = intervalCtr / 10 + " sec";

        }


        private void textBox1_TextChanged(object sender, EventArgs e)

        {

            if (textBox1.Text == label1.Text)

            {

                wctr++;

                label3.Text = "字數統計:" + wctr.ToString();

                textBox1.Text = "";

                tc++;

                tc = tc % str1.Length;

                label1.Text = str1[tc].ToString();

                label1.Top = 27;


            }

            if (!string.IsNullOrEmpty(textBox1.Text))

            {

                if (label2.Text.Contains(textBox1.Text))

                {

                    wctr++;

                    label3.Text = "字數統計:" + wctr.ToString();

                    label2.Text = label2.Text.Replace(textBox1.Text, "");

                    textBox1.Text = "";

                }

            }

        }

    }

}





2024年2月9日 星期五

2 維 list

 d =[ [0]*3 for i in range(3)]

for i in range(0,9):

    d[i//3][i%3] = i +1

for i in d:

    print(i)


print()


for i in range(0,9):

    d[i%3][i//3] = i +1

for i in d:

    print(i)

    

print()


for i in range(0,9):

    d[2-i//3][2-i%3] = i +1

for i in d:

    print(i)


print()


for i in range(0,9):

    d[2-i%3][2-i//3] = i +1

for i in d:

    print(i)


print()


a =[i+1 for i in range(9)]

# print(a)


d =[ [0]*3 for i in range(3)]

x = 1

y = 1

c=0

d[y][x] = a[c] 


for c in range(1,9):

    if x-1>=0 and d[y][x-1]<=0:

        x -=1

    elif y-1 >=0 and d[y-1][x]<=0:

        y -= 1

    elif x+1<=2 and d[y][x+1]<=0:

        x+=1

    elif y+1<=2 and d[y+1][x]<=0:

        y+=1

    d[y][x] = a[c]


for i in d:

    print(i)


print()

    

d =[ [0]*3 for i in range(3)]

x = 0

y = 0

c=0

d[y][x] = a[c] 


for c in range(1,9):

    if x-1>=0 and d[y][x-1]<=0:

        x -=1

    elif y-1 >=0 and d[y-1][x]<=0:

        y -= 1

    elif x+1<=2 and d[y][x+1]<=0:

        x+=1

    elif y+1<=2 and d[y+1][x]<=0:

        y+=1

    d[y][x] = a[c]


for i in d:

    print(i)

    

print()

d =[ [0]*3 for i in range(3)]

x = 2

y = 2

c=0

d[y][x] = a[c] 


for c in range(1,9):

    if x-1>=0 and d[y][x-1]<=0:

        x -=1

    elif y-1 >=0 and d[y-1][x]<=0:

        y -= 1

    elif x+1<=2 and d[y][x+1]<=0:

        x+=1

    elif y+1<=2 and d[y+1][x]<=0:

        y+=1

    d[y][x] = a[c]


for i in d:

    print(i)

    

    

print()

    

d =[ [0]*3 for i in range(3)]

x = 1

y = 1

c=0

d[y][x] = a[c] 


for c in range(1,9):

    if y+1<=2 and d[y+1][x]<=0:

        y+=1

    elif x-1>=0 and d[y][x-1]<=0:

        x -=1

    elif y-1 >=0 and d[y-1][x]<=0:

        y -= 1

    elif x+1<=2 and d[y][x+1]<=0:

        x+=1

    d[y][x] = a[c]


for i in d:

    print(i)

  

# 執行結果  

# [1, 2, 3]

# [4, 5, 6]

# [7, 8, 9]


# [1, 4, 7]

# [2, 5, 8]

# [3, 6, 9]


# [9, 8, 7]

# [6, 5, 4]

# [3, 2, 1]


# [9, 6, 3]

# [8, 5, 2]

# [7, 4, 1]


# [3, 4, 5]

# [2, 1, 6]

# [9, 8, 7]


# [1, 2, 3]

# [6, 5, 4]

# [7, 8, 9]


# [5, 6, 7]

# [4, 9, 8]

# [3, 2, 1]


# [5, 6, 7]

# [4, 1, 8]

# [3, 2, 9]

2024年2月7日 星期三

pyautogui sample

 import pyautogui

import time

import pyperclip


# 打開瀏覽器(這裡以Chrome為例)

pyautogui.hotkey('winleft', 'r')

pyautogui.typewrite('chrome.exe')

pyautogui.press('enter')

time.sleep(1)  # 等待瀏覽器啟動

pyautogui.press('tab')

pyautogui.press('enter')

time.sleep(1)

# pyautogui.hotkey('ctrl', 't')


# 複製文本到剪貼板

pyperclip.copy('https://www.cyvs.cy.edu.tw/home')


# 從剪貼板粘貼

# copied_text = pyperclip.paste()


# 模擬按下 Ctrl+L(選中網址列)

pyautogui.hotkey('ctrl', 'l')

time.sleep(1)  # 等待一秒,確保網址列有足夠的時間被選中


# 模擬按下 Ctrl+V(貼上內容)

pyautogui.hotkey('ctrl', 'v')


# 模擬按下 Enter(確認貼上)

pyautogui.press('enter')


time.sleep(2)  # 等待網站載入


f_button1 = pyautogui.locateOnScreen('forstu.png')

if f_button1 is not None:

    pyautogui.click(f_button1.left + 5, f_button1.top + 5)

else:

    print("找不到按鈕")