Ask a Question

How to block keyboard when script running?

SOLVED
hisense
Occasional Contributor

How to block keyboard when script running?

How to block keyboard when script running?
10 REPLIES 10
cunderw
Community Hero

Short answer you can't. Test complete sends real keystrokes and mouse actions when playing back.


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
hisense
Occasional Contributor

I do NOT think so.Without keyboard,the scripts can work normally.Any guy can show a code sample?Thanks advance!
hisense
Occasional Contributor

I do NOT think so.Without keyboard,the scripts can work normally.Any guy can show a code sample?Thanks advance!
tristaanogre
Esteemed Contributor

Right, without a physical keyboard hooked up, it will still work.  However, TestComplete "takes over" the UI input on the operating system while it's executing so any keystrokes ore mouse actions done while the automation is running will interfere.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
hisense
Occasional Contributor




the following ppython code sample dose NOT work in TestComplete ,why?
import time
from ctypes import *
user32 = windll.LoadLibrary('user32.dll')
user32.BlockInput(True);
time.sleep(10);
user32.BlockInput(False);
tristaanogre
Esteemed Contributor

Define "does not work"? Where is the error?  What error message are you getting?

 

Again... TestComplete needs to be able to interact with the objects on screen.  It needs to be able to simulate keyboard and mouse events and it does so using the operating system.  What is your purpose behind wanting to block the keyboard?  What are you trying to achieve?  Perhaps there is a better way. 


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
hisense
Occasional Contributor

Below is my answer: 1、There is no error message when running the code,it just sleep 10 seconds but the physical keyboard still can input. 2、I want to block physical keyboard input to avoid unexpected input when the scripts running. 3、TestComplete can work fine even no physical keybaord attached, so if I blocked keyboard input,it can simulate normally.
tristaanogre
Esteemed Contributor

The answer is this:

 

you can't.  Best practice is that, if an automation is running, the machine should be left untouched.  This can be done with VM's in a console mode or a lab.  


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
AlexKaras
Champion Level 2

Hi,

 

Does this help?

(Note: ages old DelphiScript code that might not work in modern TestComplete and/or Windows and I think that you definitely must consider bitness as described here: https://support.smartbear.com/testcomplete/docs/testing-with/advanced/using-external-functions/calli...)

 
//-------------------------------------------------------------------------------
// Blocks keyboard and mouse input events from reaching applications.
// Function's effect can be cancelled by pressing Ctrl-Alt-Del
procedure StopKeyMouse;
var Def_DLL;
var Def_Proc;
var Lib;
begin
    Def_DLL := DLL.DefineDLL('USER32');
    Def_Proc := Def_DLL.DefineProc('BlockInput', vt_b1, vt_b1);
    Lib := DLL.Load('USER32.DLL', 'USER32');
    Lib.BlockInput(true);
end;
//-------------------------------------------------------------------------------
 
// Unblocks keyboard and mouse input events from reaching applications.
procedure ResumeKeyMouse;
var Def_DLL;
var Def_Proc;
var Lib;
begin
    Def_DLL := DLL.DefineDLL('USER32');
    Def_Proc := Def_DLL.DefineProc('BlockInput', vt_b1, vt_b1);
    Lib := DLL.Load('USER32.DLL', 'USER32');
    Lib.BlockInput(false);
end;
//-------------------------------------------------------------------------------
 
Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
cancel
Showing results for 
Search instead for 
Did you mean: