From c993fd122bdcb252297c38ef82a3c20a324e5122 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=EB=B0=B0=EC=B0=AC=ED=9D=AC?= <cksgml3604@ajou.ac.kr>
Date: Sat, 27 Nov 2021 17:39:52 +0000
Subject: [PATCH] commit actgui

---
 actgui.py | 572 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 572 insertions(+)
 create mode 100644 actgui.py

diff --git a/actgui.py b/actgui.py
new file mode 100644
index 0000000..fc9a3ed
--- /dev/null
+++ b/actgui.py
@@ -0,0 +1,572 @@
+import time
+import math
+import pyautogui
+
+#################################################################################
+# 손동작 기록
+#00000: 기본 상태1
+#11000: 좌 클릭(clickPosX,Y,clickValue)
+#11100: 우 클릭(clickPosX,Y,clickValue)
+#10001: 드래그(dragPosX,Y), 종료
+#11001: 캡쳐(shortcut)
+#11111: 확대(toZoom, t, tm), 단축키(shortcut)(01100: 복사, 01111: 붙여넣기 11001: 캡쳐, 10001: 종료)
+#01000: 기본 상태2, 축소(toZoomOut, t, tm)
+#01100: 커서 이동(pos_2,3,time_k_p), 복사(shortcut)
+#01110: 실행취소-재실행(pos_4,5)
+#01111: 뒤로 가기-앞으로 가기(pos_6,7), 스크롤(pos6,7), 붙여넣기(shortcut)
+#-1:
+##################################################################################
+#prob
+global case
+global preCase
+case = -1
+preCase = -1
+
+#pos
+global pos
+pos = []
+
+# screen size
+screenWidth, screenHeight = pyautogui.size()
+pyautogui.moveTo(720,400)
+pyautogui.FAILSAFE = False
+
+# set pre-pos
+global pos_p2
+global pos_p3
+global pos_p4
+global pos_p5
+global pos_p6
+global pos_p7
+pos_p2 = -1.0
+pos_p3 = -1.0
+pos_p4 = -1.0
+pos_p5 = -1.0
+pos_p6 = -1.0
+pos_p7 = -1.0
+
+# set drag position
+global dragPosX
+global dragPosY
+dragPosX = -1.0
+dragPosY = -1.0
+
+# set click position
+global clickPosX
+global clickPosX
+global clickValue
+clickPosX = -1.0
+clickPosY = -1.0
+clickValue = 0
+
+# set time
+global tAt1000
+global tAt1111
+global tAt11111
+global time_k_p
+global tLeftClick
+global tRightClick
+global tTermination
+
+tAt1000= 0
+tAt1111 = 0
+tAt11111 = 0
+time_k_p = 0
+tRightClick = 0
+tLeftClick = 0
+tTermination = 0
+
+# flag
+global zoomf # 0: defalt, 1: zoom, 2: zoomout
+global shortcutf # 0: defalt, 1: use shortcut
+global scrollf # 0: defalt, 1: up, 2: down
+global zeroCount
+zoomf = 0
+shortcutf = 0
+scrollf = 0
+zeroCount = 0
+
+def store_pos(Pos):
+    global pos
+    pos = Pos
+
+def hand_check(prob):
+    global case
+    if ((prob[0] == 0.0)&(prob[1] == 0.0)&(prob[2] == 0.0)&(prob[3] == 0.0)&(prob[4] == 0.0)):
+        case = 0
+        return 0
+    if ((prob[0] == 0.0)&(prob[1] == 1.0)&(prob[2] == 0.0)&(prob[3] == 0.0)&(prob[4] == 0.0)):
+        case = 1000
+        return 1000
+    if ((prob[0] == 0.0)&(prob[1] == 1.0)&(prob[2] == 1.0)&(prob[3] == 0.0)&(prob[4] == 0.0)):
+        case = 1100
+        return 1100
+    if ((prob[0] == 0.0)&(prob[1] == 1.0)&(prob[2] == 1.0)&(prob[3] == 1.0)&(prob[4] == 0.0)):
+        case = 1110
+        return 1110
+    if ((prob[0] == 0.0)&(prob[1] == 1.0)&(prob[2] == 1.0)&(prob[3] == 1.0)&(prob[4] == 1.0)):
+        case = 1111
+        return 1111
+    if ((prob[0] == 1.0)&(prob[1] == 1.0)&(prob[2] == 1.0)&(prob[3] == 1.0)&(prob[4] == 1.0)):
+        case = 11111
+        return 11111
+    if ((prob[0] == 1.0)&(prob[1] == 1.0)&(prob[2] == 0.0)&(prob[3] == 0.0)&(prob[4] == 0.0)):
+        case = 11000
+        return 11000
+    if ((prob[0] == 1.0)&(prob[1] == 1.0)&(prob[2] == 1.0)&(prob[3] == 0.0)&(prob[4] == 0.0)):
+        case = 11100
+        return 11100
+    if ((prob[0] == 1.0)&(prob[1] == 0.0)&(prob[2] == 0.0)&(prob[3] == 0.0)&(prob[4] == 1.0)):
+        case = 10001
+        return 10001
+    if ((prob[0] == 1.0)&(prob[1] == 1.0)&(prob[2] == 0.0)&(prob[3] == 0.0)&(prob[4] == 0.0)):
+        case = 11000
+        return 11000
+    if ((prob[0] == 1.0)&(prob[1] == 1.0)&(prob[2] == 0.0)&(prob[3] == 0.0)&(prob[4] == 1.0)):
+        case = 11001
+        return 11001
+    if ((prob[0] == 1.0)&(prob[1] == 1.0)&(prob[2] == 1.0)&(prob[3] == 1.0)&(prob[4] == 0.0)):
+        case = 11110
+        return 11110
+    case = -1
+    return -1
+
+
+
+def initialize_coordinate():
+    # 좌표 초기화
+    currentMouseX, currentMouseY = pyautogui.position()
+    if (currentMouseX > screenWidth-1):
+        pyautogui.moveTo(screenWidth-1, currentMouseY)
+        
+    currentMouseX, currentMouseY = pyautogui.position()
+    if (currentMouseY > screenHeight-1):
+        pyautogui.moveTo(currentMouseX, screenHeight-1)
+    
+    currentMouseX, currentMouseY = pyautogui.position()
+    if (currentMouseX < 0):
+        pyautogui.moveTo(0, currentMouseY)
+        
+    currentMouseX, currentMouseY = pyautogui.position()
+    if (currentMouseY < 0):
+        pyautogui.moveTo(currentMouseX, 0)
+
+
+
+def initialize_variable():
+    if (case == preCase):
+        global pos_p2
+        global pos_p3
+        global pos_p4
+        global pos_p5
+        global pos_p6
+        global pos_p7
+        
+        global time_k_p
+        
+        global clickPosX
+        global clickPosY
+        global clickValue
+        
+        global scrollf
+        global zoomf
+        
+        if (case != 0):
+            zeroCount = 0
+            
+        if (case != 1000 and case != 11111):
+            zoomf = 0
+            
+        if (case != 1000 and case != 1111):
+            scrollf = 0
+            
+        if (case != 11111 and case != 1100 and case != 1111 and case != 11001):
+            shortcutf = 0
+        
+        if (case != 1100):
+            pos_p2 = -1.0
+            pos_p3 = -1.0
+            time_k_p = 0
+
+        if (case != 1110):
+            pos_p4 = -1.0
+            pos_p5 = -1.0
+          
+        if (case != 1111):
+            pos_p6 = -1.0
+            pos_p7 = -1.0
+            
+        if (case != 11000 and case != 11100 and case != 11110):
+            clickPosX = -1.0
+            clickPosY = -1.0
+            clickValue = 0
+        
+
+def terminate_check():
+    if (shortcutf == 1 and case == 10001):
+        # 종료
+        global tTermination
+        if (tTermination == 0):
+            tTermination = time.time()
+        
+        t = time.time() - tTermination
+        if (t >= 2):
+            tTermination = 0
+        if (t > 1 and t < 2):
+            print("Termination")
+            return True
+    return False
+    
+
+
+def hand_speed(diff_pos2, diff_pos3):
+    diff_t = time.time() - time_k_p
+    d = math.sqrt(pow(diff_pos2,2) + pow(diff_pos3,2))
+    v = d / diff_t
+    if(v > 800): mult_v = 2.0
+    elif (v <= 800 and v > 400): mult_v = 1.5
+    elif (v <= 400 and v > 100): mult_v = 1.0
+    else: mult_v = 0.5
+    return mult_v
+    
+    
+
+##########################################
+# 뒤에 shortcut = 0
+##########################################
+def shortcut():
+    if (shortcutf == 1):
+        if (case == 1100):
+            # 단축키 복사
+            pyautogui.hotkey('command','c')
+        
+        if (case == 1111):
+            # 단축키 붙여넣기
+            pyautogui.hotkey('command','v')
+            
+        if (case == 11001):
+            # 단축키 캡쳐
+            print("capture")
+            pyautogui.hotkey('command', 'shift', '4')
+    
+    
+    
+##########################################
+# true이면 pos_p67 갱신
+##########################################
+def forward_back(diff_pos6):
+    if (abs(diff_pos6) > 200.0):
+        # 가로
+        if (diff_pos6 > 0):
+            print("back")
+            pyautogui.hotkey('command','[')
+        elif (diff_pos6 < 0):
+            print("forward")
+            pyautogui.hotkey('command',']')
+        return True
+    return False
+
+
+
+
+##########################################
+# true이면 pos_p67 갱신
+##########################################
+def scroll():
+    print("scroll")
+    if (scrollf == 1):
+        pyautogui.scroll(5)
+    elif (scrollf == 2):
+        pyautogui.scroll(-5)
+
+
+##########################################
+# true이면 pos_p45 갱신
+##########################################
+def undo_redo(diff_pos4):
+    if (abs(diff_pos4) > 200.0):
+        # 가로
+        if (diff_pos4 > 0):
+            print("undo")
+            pyautogui.hotkey('command','z')
+        elif (diff_pos4 < 0):
+            print("redo")
+            pyautogui.hotkey('command', 'shift', 'z')
+        return True
+    return False
+    
+    
+    
+##########################################
+# 좌클릭
+##########################################
+def left_click():
+    global tLeftClick
+    if (clickValue != 1):
+        if (tLeftClick == 0):
+            tLeftClick = time.time()
+        
+        t = time.time() - tLeftClick
+        if (t >= 2):
+            tLeftClick = time.time()
+        elif (t > 0.4 and t < 2):
+#            currentMouseX, currentMouseY = pyautogui.position()
+#            if (clickPosX != currentMouseX or clickPosY != currentMouseY):
+            pyautogui.click(button='left')
+            return True
+    return False
+    
+        
+        
+##########################################
+# 우클릭
+##########################################
+def right_click():
+    if (clickValue != 2):
+#        currentMouseX, currentMouseY = pyautogui.position()
+#        if (clickPosX != currentMouseX or clickPosY != currentMouseY):
+        pyautogui.click(button='right')
+        return True
+    return False
+        
+
+
+##########################################
+# false 시 dragPosX,Y 갱신, print("remeber")
+# true 시 dragPosX,Y 초기화
+###############################################
+def drag():
+    if (dragPosX == -1.0 and dragPosY == -1.0):
+        return False
+        
+    currentMouseX, currentMouseY = pyautogui.position()
+    if (abs(currentMouseX - dragPosX) > 0 or abs(currentMouseY - dragPosY) > 0):
+        pyautogui.moveTo(dragPosX, dragPosY)
+        pyautogui.dragTo(currentMouseX, currentMouseY,2, button='left')
+        return True
+        
+
+def zoom():
+    if (zoomf == 1):
+        pyautogui.hotkey('command','+')
+    elif (zoomf == 2):
+        pyautogui.hotkey('command','-')
+
+
+
+##########################################
+# true 시
+# pos_p2 = pos[2]
+# pos_p3 = pos[3]
+# time_k_p = time.time()
+##########################################
+def move_cursor(diff_pos2, diff_pos3):
+    if (abs(diff_pos2) > 10.0 or abs(diff_pos3) > 10.0):
+        # 속도 구하기
+        mult_v = hand_speed(diff_pos2, diff_pos3)
+        
+        currentMouseX, currentMouseY = pyautogui.position()
+        
+        if (abs(diff_pos2) > 10.0 and abs(diff_pos3) > 10.0):
+            nextX = (screenWidth - 1) if currentMouseX-int(diff_pos2*mult_v) > screenWidth-1 else (currentMouseX - int(diff_pos2)*mult_v)
+            nextY = (screenHeight - 1) if currentMouseY-int(diff_pos3*mult_v) > screenHeight-1 else (currentMouseY - int(diff_pos3)*mult_v)
+            nextX = 0 if nextX < 0 else nextX
+            nextY = 0 if nextY < 0 else nextY
+            pyautogui.moveTo(nextX, nextY, 0.2)
+            return True
+            
+        elif (abs(diff_pos2) > 10.0): # 상하
+            nextX = (screenWidth - 1) if currentMouseX-int(diff_pos2*mult_v*1.5) > screenWidth-1 else (currentMouseX - int(diff_pos2)*mult_v*1.5)
+            nextX = 0 if nextX < 0 else nextX
+            nextY = currentMouseY
+            pyautogui.moveTo(nextX, nextY, 0.2)
+            return True
+            
+        elif (abs(diff_pos3) > 10.0): # 좌우
+            nextX = currentMouseX
+            nextY = (screenHeight - 1) if currentMouseY-int(diff_pos3*mult_v) > screenHeight-1 else (currentMouseY - int(diff_pos3)*mult_v)
+            nextY = 0 if nextY < 0 else nextY
+            pyautogui.moveTo(nextX, nextY, 0.2)
+            return True
+    else: return False
+
+
+
+def act_gui():
+    global preCase
+    
+    global pos_p2
+    global pos_p3
+    global pos_p4
+    global pos_p5
+    global pos_p6
+    global pos_p7
+    
+    global dragPosX
+    global dragPosY
+    
+    global clickValue
+    global clickPosX
+    global clickPosY
+    
+    global tAt1000
+    global tAt1111
+    global tAt11111
+    global time_k_p
+    global tLeftClick
+    global tRightClick
+    
+    global zoomf
+    global shortcutf
+    global scrollf
+            
+    if (case == 1000):
+        if (zoomf == 2):
+            zoom()
+            tAt1000 = time.time()
+        elif (scrollf == 2):
+            scroll()
+            tAt1000 = time.time()
+        elif (time.time() - tAt11111 < 1):
+            zoomf = 2
+        elif (time.time() - tAt1111 < 1):
+            scrollf = 2
+        else:
+            scrollf = 0
+            zoomf = 0
+            tAt1000 = time.time()
+            
+    elif (case == 1100):
+        #단축키 복사
+        ##########################################
+        # 뒤에 shortcutf = 0
+        ##########################################
+        shortcut()
+        shortcutf = 0
+        
+        if (pos_p2 == -1.0 and pos_p3 == -1.0):
+            pos_p2 = pos[2]
+            pos_p3 = pos[3]
+            time_k_p = time.time()
+            
+        diff_pos2 = pos_p2 - pos[2]
+        diff_pos3 = pos_p3 - pos[3]
+        
+        # 커서 이동
+        ##########################################-
+        # true 시
+        # pos_p2 = pos[2]
+        # pos_p3 = pos[3]
+        # time_k_p = time.time()
+        ##########################################
+        bool = move_cursor(diff_pos2, diff_pos3)
+        if (bool):
+            pos_p2 = pos[2]
+            pos_p3 = pos[3]
+            time_k_p = time.time()
+        
+    elif (case == 1110):
+        if (pos_p4 == -1.0 and pos_p5 == -1.0):
+            pos_p4 = pos[4]
+            pos_p5 = pos[5]
+                            
+        diff_pos4 = pos_p4 - pos[4]
+            
+        # 재실행, 실행취소
+        ##########################################
+        # true이면 pos_p45 갱신
+        ##########################################
+        bool = undo_redo(diff_pos4)
+        if (bool):
+            pos_p4 = pos[4]
+            pos_p5 = pos[5]
+        
+    elif (case == 1111):
+        if (shortcutf == 1):
+            # 단축키 붙여넣기
+            ##########################################
+            # 뒤에 shortcutf = 0
+            ##########################################
+            shortcut()
+            shortcutf = 0
+            
+        elif (scrollf == 1):
+            scroll()
+            tAt1111 = time.time()
+        elif (time.time() - tAt1000 < 1):
+            scrollf = 1
+        else:
+            scrollf = 0
+            tAt1111 = time.time()
+
+            if (pos_p6 == -1.0 and pos_p7 == -1.0):
+                pos_p6 = pos[6]
+                pos_p7 = pos[7]
+
+            diff_pos6 = pos_p6 - pos[6]
+            diff_pos7 = pos_p7 - pos[7]
+
+            # 앞으로 뒤로 가기
+            ##########################################
+            # true이면 pos_p67 갱신
+            ##########################################
+            bool = forward_back(diff_pos6)
+            if (bool):
+                pos_p6 = pos[6]
+                pos_p7 = pos[7]
+            
+    elif (case == 11111):
+        if (zoomf == 1):
+            zoom()
+            tAt11111 = time.time()
+        elif (time.time() - tAt1000 < 1):
+            zoomf = 1
+        else:
+            zoomf = 0
+            tAt11111 = time.time()
+        shortcutf = 1
+            
+    elif (case == 11000):
+        bool = left_click()
+        if (bool):
+                currentMouseX, currentMouseY = pyautogui.position()
+                clickPosX = currentMouseX
+                clickPosY = currentMouseY
+                clickValue = 1
+        
+    elif (case == 11100 or case == 11110):
+        bool = right_click()
+        if (bool):
+                currentMouseX, currentMouseY = pyautogui.position()
+                clickPosX = currentMouseX
+                clickPosY = currentMouseY
+                clickValue = 2
+                
+    elif (case == 10001):
+        if (shortcutf == 0):
+            # 드래그
+            ##########################################
+            # false 시 dragPosX,Y 갱신, print("remeber")
+            # true 시 dragPosX,Y 초기화
+            ##########################################
+            bool = drag()
+
+            if (bool):
+                dragPosX = -1.0
+                dragPosY = -1.0
+            else:
+                print ("remember")
+                currentMouseX, currentMouseY = pyautogui.position()
+                dragPosX = currentMouseX
+                dragPosY = currentMouseY
+            
+    elif (case == 11001):
+        # 단축키 캡쳐
+        ##########################################
+        #뒤에 shortcutf = 0
+        ##########################################
+        shortcut()
+        shortcutf = 0
+        
+    preCase = case
+
-- 
GitLab