How to keep Microsoft teams status active?

Viewed 3100

In Microsoft Teams, the status changes to "away" after a while being inactive.

Is there any way in Python to keep it active all the time?

7 Answers

Best way For Windows without Python

copy the below code and save the file as .ps1 extension

After saving file, Right click on it and select Run With PowerShell

Clear-Host
Echo "toggling scroll lock"
$WShell = New-Object -com "Wscript.Shell"
while ($true) {
$WShell.sendkeys("{SCROLLLOCK}")
Start-Sleep -Milliseconds 200
$WShell.sendkeys("{SCROLLLOCK}")
Start-Sleep -Seconds 350
}

one way worked for me on windows


Python3 Windows

this will keep your windows awake and prevent it from locking/hibernating

#Devil
import ctypes
import sys

#use this to reset the status
def display_reset():
    ctypes.windll.kernel32.SetThreadExecutionState(0x80000000)
    sys.exit(0)

def display_on():
    print("Always On")
    ctypes.windll.kernel32.SetThreadExecutionState(0x80000002)

display_on()

This works for me in Fedora. Just send the main Teams process a SIGUSR1 before the status changes. The script will continue in the background.

#!/bin/bash

signal() {
  while sleep 60 ; do
    kill ${1} ${2} || exit 0
  done
}

PID=$(pgrep -f 'teams.*disable-setuid-sandbox')

[ -z "${PID}" ] && {
  echo "${0}: Teams process not found" >&2
  exit 1
}

(signal -SIGUSR1 ${PID}&)&

Use the Pyautogui library and datetime

Set a loop that will move the mouse and click. Set it to end when an instantiated time variable equals whatever time is applicable. Ctrl/alt/delete when you return to your work station to break the loop

This can effectively keep you active in less than 11 lines of code

GUI Application to keep windows active


Python3

install library

pip install pywin32

save below code as alive.pyw file

from ctypes import windll, wintypes, byref, c_uint, sizeof, Structure
import tkinter as tk
import ctypes
import sys
import threading
import time
import win32api
import win32con


stop_threads = True
SET_IDLE_TIME = 40 #in seconds

class LASTINPUTINFO(Structure):
    _fields_ = [
        ('cbSize', c_uint),
        ('dwTime', c_uint),
    ]

def get_idle_duration():
    lastInputInfo = LASTINPUTINFO()
    lastInputInfo.cbSize = sizeof(lastInputInfo)
    windll.user32.GetLastInputInfo(byref(lastInputInfo))
    millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
    return millis / 1000.0


def press_key_2():
    global stop_threads
    while True:
        if not stop_threads:
            break
        idle_time = get_idle_duration() #seconds
        time.sleep(0.1)
        if idle_time < SET_IDLE_TIME:
            continue

        print("in ideal state pressing cltr")
        win32api.keybd_event(ord('x'), 0, win32con.KEYEVENTF_EXTENDEDKEY, 0)


#---------------- Monitor threads ------------------------------

t1 = threading.Thread(target=press_key_2, name='t1')
t1.daemon = True

#----------------- TK functions ----------------------

def display_on():
    global tk, t1, stop_threads
    stop_threads = True
    print("Always On")
    ctypes.windll.kernel32.SetThreadExecutionState(0x80000002)
    root.iconify()
    t1.start()
    # t2.start()

def display_reset():
    print("quit pressed")
    global stop_threads
    stop_threads = False
    ctypes.windll.kernel32.SetThreadExecutionState(0x80000000)
    sys.exit(0)



root = tk.Tk()
root.geometry("200x110")
root.title("Display App")
frame = tk.Frame(root)
frame.pack()

var = tk.StringVar()
label = tk.Label(frame, textvariable =  var)#, bd = 5, justify = tk.RIGHT, padx = 10, pady = 10)
var.set("")
button = tk.Button(frame,
                   text="Quit",
                   fg="red",
                   command=display_reset)

slogan = tk.Button(frame,
                   text="Always ON",
                   command=display_on)

label.pack(side=tk.BOTTOM,padx=0, pady=0)
slogan.pack(side=tk.LEFT,padx=15, pady=20)
button.pack(side=tk.LEFT,padx=15, pady=20)

root.mainloop()
ctypes.windll.kernel32.SetThreadExecutionState(0x80000000)
//Create Windows Form project in Visual Studio using C#
//Make sure this form is in focus while the project is running

    using System;
    using System.Windows.Forms;
    
    namespace MsTeamsAvailable
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                var startTimeSpan = TimeSpan.Zero;
                var periodTimeSpan = TimeSpan.FromMinutes(4);
                var timer = new System.Threading.Timer((e) =>
                {
                    MyMethod();
                }, null, startTimeSpan, periodTimeSpan);
            }
            private void MyMethod()
            {
                SendKeys.SendWait("{ENTER}");
            }
        }
    }
Related