Esempio n. 1
0
def main():
    keyboard = Controller()
    print('Press f2 to type the text of content.txt file.')
    while True:
        stop = False
        with Listener(on_press=process_keys) as listener:
            listener.join()
        with open('content.txt', 'r') as file:
            while True:
                data = file.read(512)
                if not data:
                    break
                keyboard.type(data)
                time.sleep(0.5)
Esempio n. 2
0
class AutoTyper(object):
    def __init__(self):
        self.keyboardCtrl = Controller()
        self.prettyPrintString = ""
        self.playersInfo = []
        self.ingameTimerTotalSeconds = 0

        self.listener = keyboard.Listener(on_press=self.on_press)
        self.listener.start()

    def on_press(self, key):
        try:
            if key == keyboard.Key.f12:
                self.printPrettyString()
        except AttributeError:
            print('special key {0} pressed'.format(key))

    def update_prettyPrintString(self, playersInfo, ingameTimerTotalSeconds):
        self.playersInfo = playersInfo
        self.ingameTimerTotalSeconds = ingameTimerTotalSeconds

    def printPrettyString(self):
        self.prettyPrintString = ""
        for idx, player in enumerate(self.playersInfo):
            summSpells = player.summonerSpells
            CDs = player._getCooldowns()
            if CDs[0] > 5 and CDs[1] > 5:
                minutes1, seconds1 = self.secondsToMinutes(
                    round(CDs[0] + self.ingameTimerTotalSeconds))
                minutes2, seconds2 = self.secondsToMinutes(
                    round(CDs[1] + self.ingameTimerTotalSeconds))
                self.prettyPrintString += f"{Consts.ChampionShortNames[player.champName]}: {Consts.SummonerShortNames[summSpells[0]]} {minutes1:02}:{seconds1:02}, {Consts.SummonerShortNames[summSpells[1]]} {minutes2:02}:{seconds2:02}. "
            elif CDs[0] > 5:
                minutes1, seconds1 = self.secondsToMinutes(
                    round(CDs[0] + self.ingameTimerTotalSeconds))
                self.prettyPrintString += f"{Consts.ChampionShortNames[player.champName]}: {Consts.SummonerShortNames[summSpells[0]]} {minutes1:02}:{seconds1:02}. "
            elif CDs[1] > 5:
                minutes2, seconds2 = self.secondsToMinutes(
                    round(CDs[1] + self.ingameTimerTotalSeconds))
                self.prettyPrintString += f"{Consts.ChampionShortNames[player.champName]}: {Consts.SummonerShortNames[summSpells[1]]} in {minutes2:02}:{seconds2:02}. "

        self.keyboardCtrl.type(f"{self.prettyPrintString}")

    def secondsToMinutes(self, secondsTotal):
        """

        :param secondsTotal:
        :return:
        """
        return int(secondsTotal / 60), int(secondsTotal % 60)
Esempio n. 3
0
class Spammer:
    def __init__(self,
                 text="Sample Text",
                 spamc=1,
                 init_delay=5,
                 is_splitted=False,
                 suffix="\n",
                 single_delay=0):
        self.text = text
        self.spamc = spamc
        self.init_delay = init_delay
        self.is_splitted = is_splitted
        self.suffix = suffix
        self.single_delay = single_delay
        self.keyboard = Controller()

    def run(self):
        prg = Progressbar()
        prg.run(self._sprun, self.init_delay)

    def _sprun(self):
        for count in range(self.spamc):
            if (self.is_splitted):
                splitted = self.text.split(" ")
                for x in splitted:
                    self.keyboard.type(x)
                    self.keyboard.type(self.suffix)
            else:
                self.keyboard.type(self.text)
                self.keyboard.type(self.suffix)
            time.sleep(self.single_delay)
Esempio n. 4
0
    def keyboardPrint(cls, msg, keyboardObject=None):
        if keyboardObject == None:
            keyboard = Controller()
        else:
            keyboard = keyboardObject
        keyboard.type(msg)


#test for keyboardController
# keyboard=keyboardController.createKeyboardObject()
# mouseController.mouseLeftClick()
# keyboardController.keyboardPressKey('A',keyboard)
# keyboardController.keyboardReleaseKey('A',keyboard)
# keyboardController.keyboardPrint('hello world!',keyboard)
def upload_defintion(driver, template_path, diagram_name):
    upload_definition_button = driver.find_element_by_id('SplitMain_ContentPlaceHolderBodyRight_ContentTabControl_ContentTabCallBackPanel_ContentPanel_ctl07_InstContentPanel_InstFolderDisplay_InstFolderDisplayCP_ctl00_ctl00_ctl00')
    upload_definition_button.click()

    af.waitForElement(driver, 10, By.ID,"SplitMain_ContentPlaceHolderBodyRight_ContentTabControl_ContentTabCallBackPanel_ContentPanel_ctl07_InstContentPanel_FileUploadCtrl_FileUploadPopUp_UploadCtrl_TextBox0_FakeInput")
    upload_definition_box = driver.find_element_by_id('SplitMain_ContentPlaceHolderBodyRight_ContentTabControl_ContentTabCallBackPanel_ContentPanel_ctl07_InstContentPanel_FileUploadCtrl_FileUploadPopUp_UploadCtrl_Browse0')
    upload_definition_box.click()
    time.sleep(2)

    # simulating the keyboard to enter the path and file name for the upload

    keyboard = Controller()
    keyboard.type(template_path)
    keyboard.press(Key.enter)
    keyboard.release(Key.enter)

    # should entering the path not work the programm will try a second time
    # if it still dosen't work it will close the upload window and reutrn false
    if not af.waitForElement(driver, 10, By.ID, "contentDlgSaveAs"):
        keyboard.press(Key.enter)
        keyboard.release(Key.enter)
        keyboard = Controller()
        keyboard.type(template_path)
        keyboard.press(Key.enter)
        keyboard.release(Key.enter)
        if not af.waitForElement(driver, 10, By.ID, "contentDlgSaveAs"):
            keyboard.press(Key.enter)
            keyboard.release(Key.enter)
            # presses three times tab and on time enter to close the upload window
            for i in range(3):
                keyboard.press(Key.tab)
                keyboard.release(Key.tab)
            keyboard.press(Key.enter)
            keyboard.release(Key.enter)
            driver.find_element_by_xpath("//*[@id='SplitMain_ContentPlaceHolderBodyRight_ContentTabControl_ContentTabCallBackPanel_ContentPanel_ctl07_InstContentPanel_FileUploadCtrl_FileUploadPopUp_PWH-1']/table/tbody/tr/td[2]/img").click()
            return False
    # wirtes the diagram_name into the name field
    Name_field = driver.find_element_by_xpath("//*[@id='contentDlgSaveAsNewName']")
    Name_field.clear()
    Name_field.send_keys(diagram_name)
    save_as_private = driver.find_element_by_xpath(".//*[@value = 'private']")
    save_as_private.click()
    # enter press to confirm upload
    #keyboard.press(Key.enter)
    #keyboard.release(Key.enter)
    save_button = driver.find_element_by_xpath(".//*[text() = 'Speichern'][ @type='button']")
    save_button.click()
    af.wait_loading_finished(driver, 1)
    return True
Esempio n. 6
0
def main():
    mouse = Mouse()
    mouse.move(450, 450)
    mouse.press(Button.left)
    mouse.release(Button.left)

    time.sleep(2)

    keyboard = Keyboard()
    keyboard.type('sunny')
    keyboard.press(Key.space)
    keyboard.release(Key.space)

    keyboard.press(Key.enter)
    keyboard.release(Key.enter)
Esempio n. 7
0
class MainCLS(object):
    def __init__(self):

        print('Waiting for key ...')

        self.keyboard = Controller()
        with Listener(on_press=self.onPress) as listener:
            listener.join()

    def onPress(self, key):

        if (key == Key.f4):
            print('Simulating keys ... ', end='')
            self.keyboard.type(pyperclip.paste())
            print('OK')
Esempio n. 8
0
def main():
    should_tts = True
    keyboard = Controller()
    delay = 2 #adjust to get into your chosen platform
    time.sleep(delay)

    file = open("bee_movie_script.txt", "r")
    
    for line in file:
        
        if(not line.isspace()):
            if(should_tts): keyboard.type("/tts ")
            keyboard.type(line)
            delay = random.randrange(1, 3)
            time.sleep(delay)
Esempio n. 9
0
def main():

    # time to switch over to the Messenger app and rethink your life
    time.sleep(3)

    # setup
    keyboard = Controller()
    words = separateText(open("text.txt", "r").read())

    # type the words into the messenger app and hit return after every word. delay a tenth of a second per word
    for word in words:
        keyboard.type(word)
        keyboard.press(Key.enter)
        keyboard.release(Key.enter)
        time.sleep(0.1)
def typein():
    try:
        while 1:
            text = Audio.get_audio()
            k=Controller()

            if text in strlists.VOICETYPING_KEYPRESSES_STR:
                for phrase in strlists.VOICETYPING_KEYPRESSES_STR:
                    
                    if "select all" in text:
                        pyautogui.hotkey('ctrl','a')
                    elif "undo" in text:
                        pyautogui.hotkey('ctrl','z')
                    elif "redo" in text:
                        pyautogui.hotkey('ctrl','y')
                    elif "copy" in text:
                        pyautogui.hotkey('ctrl','c')
                    elif "paste" in text:
                        pyautogui.hotkey('ctrl','v')
                    elif "italic" in text:
                        pyautogui.hotkey('ctrl','i')
                    elif "cut" in text:
                        pyautogui.hotkey('ctrl','x')
                        pass

                    elif phrase in text:
                        pyautogui.press(phrase)
                    
            
            
            elif 'switch off voice typing' in text:
                engine.speak("getting out of voice typing master")
                time.sleep(2)
                break

            else:
                k.type(text)
                continue


                        
                        
    
    
    except:
        engine.speak("something went wrong master!!")

        
Esempio n. 11
0
def output_macro(activated_macro, output_dict):
    '''
    Checks output_dict for the key activated_macro\n
    then outputs the value of activated_macro to the keyboard/n
    using pynput macro_output controller
    '''
    print(activated_macro)
    print(output_dict)
    activated_macro = str(activated_macro)
    macro_value = output_dict[activated_macro]
    macro_output = Controller()
    print(macro_value)
    macro_output.type(macro_value)
    print(
        f'macro alt_r + {activated_macro}:\'{macro_value}\' has been activated'
    )
Esempio n. 12
0
def start_plot(delay=DELAY):
    global run

    keyboard = Controller()  # The keyboard controlling class
    for filename in os.listdir(save_dir):
        if run:
            if ".pickle" in filename:  # Prevent .DS_Store from loading
                obj = load_object(filename)
                function_string = obj.write_function()

                keyboard.type(function_string)
                keyboard.press(Key.enter)
                time.sleep(delay)
                obj.remove()
        else:
            break
Esempio n. 13
0
def _key_change_callback(deck_id: str, _deck: StreamDeck.StreamDeck,
                         button_id: int, state: bool) -> None:
    if state:
        keyboard = Controller()
        page = get_page(deck_id)
        key = f"{deck_id}.{page}.{button_id}"

        command = get_button_command(deck_id, page, button_id)
        if command:
            try:
                if key in command_handler:
                    command_handler[key].kill()
                    command_handler[key].communicate()
                    command_handler.pop(key)
                else:
                    command_handler[key] = Popen(command.split(" "),
                                                 cwd=Path.home())
            except Exception as error:  # catch invalid commands
                warn(
                    f"Running the provided command {command} raised a {error} exception."
                )
            if _button_state(deck_id, page, button_id).get("toggle", False):
                image_cache.pop(key)
                render()

        keys = get_button_keys(deck_id, page, button_id)
        if keys:
            keys = keys.strip().replace(" ", "")
            for section in keys.split(","):
                for key_name in section.split("+"):
                    keyboard.press(getattr(Key, key_name.lower(), key_name))
                for key_name in section.split("+"):
                    keyboard.release(getattr(Key, key_name.lower(), key_name))

        write = get_button_write(deck_id, page, button_id)
        if write:
            keyboard.type(write)

        brightness_change = get_button_change_brightness(
            deck_id, page, button_id)
        if brightness_change:
            change_brightness(deck_id, brightness_change)

        switch_page = get_button_switch_page(deck_id, page, button_id)
        if switch_page:
            set_page(deck_id, switch_page - 1)
Esempio n. 14
0
def getValues():
    keyboard = Controller()
    keyboard.press(Key.enter)
    keyboard.type("/getcoords")
    keyboard.press(Key.enter)

    time.sleep(0.5)

    screen = np.array(ImageGrab.grab())
    screen = screen[y:y + h, x:x + w]

    new_screen = process_img(screen)

    #cv2.imshow('window', new_screen)
    i, j, a = getValuesFromImage(new_screen)
    #print(str(i)+" "+str(j)+" "+str(a))
    return x, y, a
Esempio n. 15
0
class KeyboardController():
    def __init__(self):
        self.moose = "yeah"
        self.keyboard = Controller()

    def press(self, key):
        self.keyboard.press(Key.key)

    def release(self, key):
        self.keyboard.release(Key.key)

    def press_release(self, key):
        self.keyboard.press(Key.key)
        self.keyboard.release(Key.key)

    def typeing(self, string):
        self.keyboard.type(string)
def join_lecture(code):
    """
    put this later
    """

    if len(code) > 11:  # link
        webbrowser.open(code)
        time.sleep(1)
        keyboard.press_and_release("tab")
        keyboard.press_and_release("tab")
        time.sleep(0.5)
        keyboard.press_and_release("enter")

    else:  # code
        keyboard.press_and_release("win")
        time.sleep(0.5)
        keyboard.write("start zoom")
        time.sleep(0.5)
        keyboard.press_and_release("enter")
        time.sleep(0.5)

        pyautogui.leftClick(x=816, y=396)  # join

        time.sleep(0.2)
        keyboard.write(code)
        time.sleep(0.2)
        keyboard.press_and_release("enter")

    time.sleep(6)
    pyautogui.leftClick(x=951, y=526)  # join audio\
    time.sleep(0.5)
    pyautogui.leftClick(x=951, y=526)
    time.sleep(2)

    Controller.press(Key.alt)
    Controller.type("h")

    Controller.type("sup n****s")
    #pyautogui.leftClick(x=907, y=931) # open chatbox
    #time.sleep(0.5)
    #pyautogui.leftClick(x=855, y=667) # click chat

    keyboard.write("im here n***a")
    keyboard.press_and_release("enter")
    return None
Esempio n. 17
0
def spam(string, how_long, pause, one_word_at_a_time):
    keyboard = Controller()
    word = string + ' '
    end_time = time.time() + 60 * how_long
    time.sleep(5)
    while time.time() <= end_time:
        if one_word_at_a_time:
            for letter in word:
                keyboard.type(letter)
                time.sleep(pause)
                if letter == " ":
                    keyboard.press(Key.enter)
                    keyboard.release(Key.enter)
        else:
            keyboard.type(word)
            time.sleep(pause)
            keyboard.press(Key.enter)
            keyboard.release(Key.enter)
Esempio n. 18
0
def action():
    print("Anmeldung erfolgt.")
    Popen(["C:\\Program Files (x86)\\Time-Organizer\\Time-Organizer.exe", "//einmal"])
    sleep(5)
    keyboard = Controller()
    keyboard.type("Kätzlmeier")
    sleep(1)
    keyboard.press(Key.tab)
    keyboard.release(Key.tab)
    sleep(1)
    keyboard.type("XXX")
    sleep(1)
    keyboard.press(Key.tab)
    keyboard.release(Key.tab)
    sleep(1)
    keyboard.press(Key.space)
    keyboard.release(Key.space)
    exit()
def __type_string_with_delay(text, typingDelay, startDelay):
    keyboard = Controller()
    typingDelayInSec = typingDelay / 1000
    startDelayInSec = startDelay / 1000

    # Wait for start delay (in seconds)
    print("Start delay: {}ms".format(startDelay))
    print("Delay between characters: {}ms".format(typingDelay))
    time.sleep(startDelayInSec)

    # Begin typing
    print("Typing...")

    for ch in text:
        keyboard.type(ch)
        time.sleep(typingDelayInSec)

    print("Complete! Ready for the next image!\n")
Esempio n. 20
0
def keyboard_input(string):
    '''
    :param string: 你想要发送的信息
    :return: None
    '''

    #导入相应的库
    次数 = int(input("请输入你要轰炸的次数:"))
    time.sleep(2)
    gui.hotkey('ctrl', 'alt', 'z')
    while True:
        keyboard = Controller()  #开始控制键盘
        keyboard.type(string)  #键盘输入string
        gui.hotkey('enter')
        次数 -= 1
        if 次数 == 0:
            break
    return None
Esempio n. 21
0
def shellSlave(masterConn):
    confirm = reciveMsg(masterConn)
    cwd = os.getcwd()
    name = os.environ['COMPUTERNAME']
    print("No he mandado nada")
    sendMsg(masterConn, cwd)  #Sending current working directory
    print("Ya mande cwd")
    sendMsg(masterConn, name)
    print("Ya mande name")
    connect = True
    presser = Controller()
    while connect:
        command = reciveMsg(masterConn)
        if (command == "exit"):
            connect = False
        elif command[:2] == "cd" and len(command) > 2:
            try:
                os.chdir(command[3:])
                cwd = os.getcwd()
                sendMsg(masterConn, cwd)
            except:
                print(ERROR_DIR)
                sendMsg(masterConn, ERROR_DIR)
        elif command[:9] == "download ":
            try:
                sendFile(masterConn, command[9:])
            except:
                masterConn.send(ERROR_FILE.encode(FORMAT))
        elif command[:5] == "type ":
            presser.type(command[5:])
            presser.press(Key.enter)
            sendMsg("Pressed")
        elif command[:6] == "press ":
            for character in command[6:]:
                presser.press(character)
            presser.press(Key.enter)
            sendMsg("Pressed")
        else:
            process = subprocess.run(command,
                                     capture_output=True,
                                     text=True,
                                     shell=True)
            msg = process.stdout + process.stderr
            sendMsg(masterConn, msg)
Esempio n. 22
0
def take_action(selected_box, last_action, mode):
    action = None
    if selected_box:
        action = selected_box.action

    if action:
        if ACTION_MODE == 0 and action != last_action:
            print('Tapping :', action)
            keyboard = Controller()
            keyboard.type(action)
            # keyboard.press(action)
            # keyboard.release(action)
        if ACTION_MODE == 1:
            print('Holding :', action)
            keyboard = Controller()
            keyboard.type(action)
            # keyboard.press(action)
            # keyboard.release(action)
    return action
Esempio n. 23
0
def control_keypad():
    while True:
        time.sleep(60)
        keyboard = Controller()
        time.sleep(2)
        keyboard.press(Key.space)
        keyboard.release(Key.space)
        time.sleep(2)
        keyboard.press('a')
        keyboard.release('a')
        time.sleep(2)
        keyboard.press('A')
        keyboard.release('A')
        time.sleep(2)
        with keyboard.pressed(Key.shift):
            keyboard.press('a')
            keyboard.release('a')
        time.sleep(2)
        keyboard.type('Hello World!')
Esempio n. 24
0
    def drawPoniter(self, popele):
        """
        :param popele: 接受人
        :return: null
        """
        content = str(self.msgedit.toPlainText())  # 发送内容
        try:
            m = MoveTo()
            k = Thekeys()
            left, top, right, bottom = self.getWindow()  #获取微信在屏幕的坐标
            #微信搜索框  距离最最左边是100左右,距离最上面25左右
            m.position = (left + 100, top + 25)
            m.click(Button.left, 1)
            time.sleep(1)

            #复制微信名称 并回车
            k.type(popele)
            k.touch(Key.enter, True)
            time.sleep(1)

            #点击搜索的微信名称
            m.position = (left + 100, top + 65)
            m.click(Button.left, 1)
            time.sleep(1)

            #复制要发送的内容
            # 复制文字到输入框
            m.position = (left + 345, bottom - 90)
            m.click(Button.left, 1)
            k.type(content)
            k.touch(Key.enter, True)
            time.sleep(1)
            #判定是否是最后一项
            dataleng = len(self.dataList) - 1
            if self.endface == dataleng:
                #关闭微信
                m.position = (left + 830, top + 10)
                m.click(Button.left, 1)
                time.sleep(1)
                self.signal_write_msg.emit('发送完毕')
        except Exception as e:
            pass
Esempio n. 25
0
def auto_type(id, password, joinposn):
    """Executes actions on Zoom.exe"""

    print("id:", id)
    keyboard = KB_Controller()
    mouse = Mouse_Controller()
    with keyboard.pressed(Key.alt_l):
        keyboard.press(Key.tab)
        keyboard.release(Key.tab)
    time.sleep(0.5)  #
    mouse.position = joinposn
    mouse.click(Button.left)
    time.sleep(1)  #
    keyboard.type(id)
    keyboard.press(Key.enter)
    keyboard.release(Key.enter)
    time.sleep(3.5)  #
    keyboard.type(password)
    keyboard.press(Key.enter)
    keyboard.release(Key.enter)
Esempio n. 26
0
class Keyboard():
    def __init__(self):
        self.keyboard = Controller()
        self.pressed = []

    def press(self, key):
        mapped_key = key_mapping.get(key, None)
        if mapped_key is None:
            return
        if mapped_key not in self.pressed:
            self.pressed.append(mapped_key)
            self.keyboard.press(mapped_key)

    def release_all(self):
        for key in self.pressed:
            self.keyboard.release(key)
            self.pressed.remove(key)

    def write(self, text):
        self.keyboard.type(text)
Esempio n. 27
0
 def post(self):
     current_time = time.strftime("%d.%m.%Y %H:%M:%S", time.localtime())
     ip = self.request.remote_ip
     username = self.get_argument('username')
     action = self.get_argument('action')
     # self.redirect('/ws')
     print("{}: {}: POST: {} {}".format(current_time, ip, username, action))
     keyboard = Controller()
     if action == 'next':
         keyboard.press(KeyCode.from_vk(0xB0))
     elif action == 'prev':
         keyboard.press(KeyCode.from_vk(0xB1))  #0xB1 pause media
     elif action == 'hide':
         keyboard.press(Key.ctrl)
         keyboard.press(Key.space)
         keyboard.release(Key.ctrl)
         keyboard.release(Key.space)
     elif action == "log":
         keyboard.type('Hello World')
     self.write("{}: Wow {} {}".format(ip, username, action))
Esempio n. 28
0
def collect_mk():
    print("Collecting Kak...")

    m = MController()
    k = KController()

    # move mouse to message bar & click
    m.position = (-1418, 1339)
    m.click(Button.left, 1)

    # type command and press enter
    k.type(command)
    k.press(Key.enter)

    # move mouse to react location
    m.position = (-1418, 1265)

    # wait for reaction to apear and click
    time.sleep(2)
    m.click(Button.left, 1)
def login(username,password,mywait):
    try:
        keyboard = Controller()
        driver = webdriver.Chrome(
            executable_path='C:\\Users\\Arsal Azeem\\Desktop\\drivers\\chromedriver_win32\\chromedriver.exe')
        driver.get("https://dev.tradishes.com/#/host/register")
        driver.implicitly_wait(mywait)
        driver.find_element(By.XPATH, '//*[@id="loginForm"]/div[1]/label').click()
        keyboard.press(Key.tab)
        keyboard.release(Key.tab)
        keyboard.type(username)
        keyboard.press(Key.tab)
        keyboard.release(Key.tab)
        keyboard.type(password)
        driver.find_element(By.XPATH, '//*[@id="submitLoginForm"]').click()
        driver.find_element(By.XPATH,
                            '//*[@id="customer-dining-container"]/div/div/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div[2]/img').click()
        return True
    except:
        return False
Esempio n. 30
0
def user_signed_in(websiteUrl,USERNAME,PASSWORD):
    '''
    Signs in the user based on the username and password given
    '''
    driver.get(websiteUrl) #load site
    keyboard = Controller() #make keyboard

    if websiteUrl == "https://finance.yahoo.com/":
        try:
            signInButton = driver.find_element_by_id("header-signin-link")
            signInButton.click()

            textArea = WebDriverWait(driver, 10*WAIT_TIME).until(lambda x: x.find_element_by_class_name("phone-no"))
            textArea.send_keys(USERNAME) #types in username as soon as element is found within 30 seconds
            keyboard.press(Key.enter)
            keyboard.release(Key.enter)
            print("username entered.")

            textArea = WebDriverWait(driver, 10*WAIT_TIME).until(lambda x: x.find_element_by_id("login-passwd"))
            textArea.send_keys(PASSWORD) #types in username as soon as element is found within 30 seconds
            keyboard.press(Key.enter)
            keyboard.release(Key.enter)
            print("password entered.")
        except:
            driver.close()
            return False
    #testing functionality with other websites
    elif(websiteUrl == "https://www.tradingview.com/"):
        signInButton = driver.find_element_by_class_name("tv-header__link.tv-header__link--signin.js-header__signin")
        signInButton.click() #click sign in button
        
        sleep(WAIT_TIME)
        keyboard.type(USERNAME)
        keyboard.press(Key.tab)
        keyboard.release(Key.tab)
        keyboard.type(PASSWORD) 
        keyboard.press(Key.enter)
        keyboard.release(Key.enter) #wait for sign in screen to load and type in username and password and hit enter
    else:
        return False #if website is not listed 
    return True
Esempio n. 31
0
class App:
    def __init__(self, master):

        self.master = master
        self.CRNs = []
        self.keyboard = None
        self.listener_initialized = False
        master.title("CRN Automatic Paster")

        # Validation
        vcmd = (self.master.register(self.validate), '%S')
        self.v = False  # self.v = IntVar()

        label_greeting = Label(master, text="CRN Automatic Paster")

        self.e1 = Entry(master, width=10, validate="key", validatecommand=vcmd)
        self.e2 = Entry(master, width=10, validate="key", validatecommand=vcmd)
        self.e3 = Entry(master, width=10, validate="key", validatecommand=vcmd)
        self.e4 = Entry(master, width=10, validate="key", validatecommand=vcmd)
        self.e5 = Entry(master, width=10, validate="key", validatecommand=vcmd)
        self.e6 = Entry(master, width=10, validate="key", validatecommand=vcmd)
        self.e7 = Entry(master, width=10, validate="key", validatecommand=vcmd)
        self.e8 = Entry(master, width=10, validate="key", validatecommand=vcmd)
        self.e9 = Entry(master, width=10, validate="key", validatecommand=vcmd)
        self.e10 = Entry(master, width=10, validate="key", validatecommand=vcmd)

        C = Checkbutton(master, text="Press Submit after pasting", command=self.cb)  # variable=self.v
        button_done = Button(master, text="Done", command=self.done_pressed)

        label_greeting.grid(row=0, column=0, columnspan=10, pady=10)

        self.e1.grid(row=1, column=0, sticky=W, padx=7)
        self.e2.grid(row=1, column=1, sticky=W, padx=7)
        self.e3.grid(row=1, column=2, sticky=W, padx=7)
        self.e4.grid(row=1, column=3, sticky=W, padx=7)
        self.e5.grid(row=1, column=4, sticky=W, padx=7)
        self.e6.grid(row=2, column=0, sticky=W, padx=7, pady=10)
        self.e7.grid(row=2, column=1, sticky=W, padx=7)
        self.e8.grid(row=2, column=2, sticky=W, padx=7)
        self.e9.grid(row=2, column=3, sticky=W, padx=7)
        self.e10.grid(row=2, column=4, sticky=W, padx=7)

        C.grid(row=3, column=0, columnspan=2)
        button_done.grid(row=3, column=3, columnspan=2, sticky=W + E, pady=5, padx=3)

        self.generate_menu_bar()

    def done_pressed(self):
        self.CRNs = [
            self.e1.get(), self.e2.get(), self.e3.get(), self.e4.get(), self.e5.get(),
            self.e6.get(), self.e7.get(), self.e8.get(), self.e9.get(), self.e10.get()
        ]

        if not self.listener_initialized:
            self.keyboard = Controller()

            listener = Listener(on_release=self.on_release, on_press=None)
            listener.start()

            self.listener_initialized = True

    def generate_menu_bar(self):
        menu = Menu(self.master)
        self.master.config(menu=menu)
        helpmenu = Menu(menu, tearoff=0)
        menu.add_cascade(label="Help", menu=helpmenu)

        helpmenu.add_command(label="How to use", command=self.guide)
        helpmenu.add_command(label="Try it out!", command=self.demo)
        helpmenu.add_command(label="About...", command=self.about)

    def guide(self):
        guide_window = Toplevel()

        v = "1. Copy-Paste or manually input your required CRNs into the program's entry boxes.\n(Keep in mind the " \
            "CRN must not contain any spaces or characters, else they won't be accepted into the entry box)\n2. Press " \
            "the 'Done' Button\n3. Open BSS, highlight/press the FIRST entry box in BSS\n4. Press Shift (Either the " \
            "left or the right one, both work) "

        guide_text = Label(guide_window, text=v, justify=LEFT)
        guide_text.pack()

    def demo(self):
        url = "demo.html"
        webbrowser.open(url, new=2)

    def about(self):
        about_window = Toplevel()

        v = "Made by Shady Fanous\[email protected]\nSource code at " \
            "https://github.com/ShadyF/CRN_Paster\nthis tab needs to be redone "

        about_text = Label(about_window, text=v, justify=LEFT)
        about_text.pack()

    def iterate(self):
        for CRN in self.CRNs:
            if CRN:
                self.keyboard.type(CRN)
            self.keyboard.press(Key.tab)
            self.keyboard.release(Key.tab)

        # If Press enter after pasting checkbox is marked
        if self.v:
            self.keyboard.press(Key.enter)
            self.keyboard.release(Key.enter)

    @staticmethod
    def validate(s):
        return s.isdigit()

    def on_release(self, key):
        if key == Key.shift:
            self.iterate()

    def cb(self):
        self.v = not self.v