How to stop the screen saver

Hello there,
I have a small problem, i don't know how to stop screen saver with arduino.

A few words about project....
I use Arduino UNO with motion sensor that is connected to PC (+Gobetwino app). When PC starts up, windows load normally a scrren saver after 1 min (i set this in windows settings). Now, what i want to do is that, when a user is near this motion sensor, arduino should do something to stop the screen saver and user should view normal desktop. When user isn't near PC, there should be running a scrren saver.

In my code when user is near PC, and the distance between PC and user is lower than 120cm, arduino should send a command to gobetwino and gobetwino run a vbs script that simulate key press. But somethings is wrong and often screen saver is not running after user absence.

I was thinking about key pressing or mouse click without using gobetwino. But those libraries aren't compatible with Arduino UNO.

Does anyone know how to fix that? Other solutions?
In my opinion there is something wrong with code... maybe delays?
In code there are also addintional libraries for RTC but with that everything is fine.

#include <Wire.h>
#include "RTClib.h"
#include <Time.h>
#include <TimeAlarms.h>

RTC_DS1307 rtc; 

int Trig = 2;  
int Echo = 3; 
long EchoTime;  
int  Distance;  // distance in cm
int  MaximumRange = 200; // max distance
int  MinimumRange = 2;   // min distance
int  zblizenie = 0; // variable for store if user is near pc
int  temp = 0; // secondary variable for store information about position of user

void czujnikSetup(){
  pinMode(Trig, OUTPUT);
  pinMode(Echo, INPUT);

void czujnikLoop()
  // set low TRIG 2us
  digitalWrite(Trig, LOW);
  // set high TRIG 10us
  digitalWrite(Trig, HIGH);
  // set low TRIG - start measurement
  digitalWrite(Trig, LOW);
  EchoTime = pulseIn(Echo, HIGH);
  // default - we calculate the distance
  Distance = EchoTime / 58;

    if (Distance < 120){ //user is near pc
      zblizenie = 1;
    else{ //user isn't near PC
      zblizenie = 0;
  // delay between another measurement

void setThat(){
    if(temp==0){ // user isn't near pc
    else if(temp==1){ //user is near pc
      Serial.println("#S|KILL|[]#"); // send to gobetwino, gobetwino will run a script that simulate a key press so screen saver will turn off

void setup(){
  pinMode(13, OUTPUT); 

void loop(){

Perhaps you're not waiting long enough for the screen saver to activate.

I'm waiting long enough.
Other solution i've made...

if (Distance < 120){ //user is near pc
      //zblizenie = 1;
  • setThat() deleted

Even that isn't working. But should - user is near PC? Run script.
In gobetwino output i saw, that script is running and running and running all he time (even when user isn't near PC; so scrren saver will not start in the future).

Loop in loop?

I think the problem is with gobetwino and running processes.
So, my next question... is there anything that i can insert to the code and it will:

  1. simulate key press? or
  2. simulate mouse click? or
  3. simulate mouse move? or
  4. run a batch file from windows hard drive? or
  5. anything else that will abort screen saver?

It is easier with a Leonardo, because that can easily emulate mouse clicks or keyboard presses (eg. prestting Ctrl would do it).

There was a library a while back that lets you make a Uno become a USB slave.

One example: