Message everyone on your friends list automatically.

Code:
from pywinauto.findwindows    import find_window
from pywinauto.win32functions import SetForegroundWindow
import pyautogui
import time
from more_itertools import sliced
import win32api
global welcome
welcome = '''Welcome to Frixwar's Friends Messenger.
This Project was released to MPGH.NET
Please watch the video for first-time usage.
'''
def Friends_list(): #Navigates the friends list.
    SetForegroundWindow(find_window(title='Friends')) #Brings the friends list to the front.
    pyautogui.press('down')
    pyautogui.press('enter')
    time.sleep(1)   
def Second_Window(text): #Second window.
    text = list(sliced(text,250)) #Splits the string up into 250 character sized blocks. This allows the user to send a novel if they choose to do so.
    indexval = 0 #index value for splitting the string.
    for i in range(len(text)): #types the message into the chat box.    
        pyautogui.typewrite(text[indexval])
        time.sleep(.2) #Short delay to allow the message to send.
        pyautogui.press('enter')
        time.sleep(.2) #Same thing ^
        indexval += 1 #Gets the second message ready.
def get_key_press1(key):
        return win32api.GetAsyncKeyState(key)
def keyState():
    try:   
        import win32api
    except ImportError:
        win32api = None
    i = 1
    KEYS = {
        'BACK': 8,
        'TAB': 9,
        'CLEAR': 12,
        'RETURN': 13,
        'PAUSE': 19,
        'CAPSLOCK': 20,
        'ESC': 27,
        'SPACE': 32,
        'PGUP': 33,
        'PGDOWN': 34,
        'END': 35,
        'HOME': 36,
        'LEFT': 37,
        'UP': 38,
        'RIGHT': 39,
        'DOWN': 40,
        'INSERT': 45,
        'DELETE': 46,
        'LWIN': 91,
        'RWIN': 92,
        'MENU': 93,
        'NUM0': 96,
        'NUM1': 97,
        'NUM2': 98,
        'NUM3': 99,
        'NUM4': 100,
        'NUM5': 101,
        'NUM6': 102,
        'NUM7': 103,
        'NUM8': 104,
        'NUM9': 105,
        'MULTIPLY': 106,
        'ADD': 107,
        'SUBTRACT': 109,
        'DECIMAL': 110,
        'DIVIDE': 111,
        'F1': 112,
        'F2': 113,
        'F3': 114,
        'F4': 115,
        'F5': 116,
        'F6': 117,
        'F7': 118,
        'F8': 119,
        'F9': 120,
        'F10': 121,
        'F11': 122,
        'F12': 123,
        'F13': 124,
        'F14': 125,
        'F15': 126,
        'F16': 127,
        'F17': 128,
        'F18': 129,
        'F19': 130,
        'F20': 131,
        'F21': 132,
        'F22': 133,
        'F23': 134,
        'F24': 135,
        'NUMLOCK': 144,
        'SCROLLLOCK': 145,
        'LSHIFT': 160,
        'RSHIFT': 161,
        'LCTRL': 162,
        'RCTRL': 163,
        'LALT': 164,
        'RALT': 165,
        'COLON': 186,
        'EQUALS': 187,
        'COMMA': 188,
        'UNDERSCORE': 189,
        'PERIOD': 190,
        'FORWARDSLASH': 191,
        'AT': 192,
        'LBRACKET': 219,
        'BACKSLASH': 220,
        'RBRACKET': 221,
        'HASH': 222,
        'TILDE': 223
    }
    for c in list('P'):
        KEYS[c] = ord(c)
        while True:
            pressed = []
            for k in KEYS:
                if win32api:
                    if get_key_press1(KEYS[k]):
                         if k == 'P':
                            x,y = pyautogui.position()
                            return x,y
                          
def main():
    global welcome
    print(welcome)
    time.sleep(2)
    loops = int(input('How many friends do you have?\n: ')) #Asks the user how many friends they have.
    text = input('Please paste your message from Word to ensure correct grammer. :D\n: ') #Ask the user for a message, that will be sent to everyone on their friends list.
    delay = input('Please input the delay in which the program will wait to send a mesage to another user.\n: ')
    delay = int(delay)
    time.sleep(1)
    print('The Program is now looking for your first friend on your friends list.\nPlease hover over the name and push the letter "P" on your keyboard.')
    x,y = keyState()
    print('You have indicated that',x,y,'is the starting cordinates.\nThe program will start onece you press "P" again.')
    time.sleep(2)
    a,b = keyState()
    i = 6
    while i > 1 :
        i = i - 1
        print('The program is now starting in: ',i,end='\r') #Cool Countdown effect.
        time.sleep(1)
    SetForegroundWindow(find_window(title='Friends')) #brings the friends window to the front.
    time.sleep(1)
    pyautogui.doubleClick(x,y) #This allows the program to be simple when sending messages, and makes sure the first user gets the message.
    time.sleep(2)
    Second_Window(text)
    time.sleep(1)
    for i in range(0,loops): #For loop for the amount of friends you have.
        Friends_list()
        Second_Window(text)
        time.sleep(delay)
main()