Qt simulate key press to control SimpleScreenRecorder application in Linux - keypress

I want (in Linux) to control desktop recording by activating SimpleScreenRecorder with emulating key press CTRL+SHIFT+R.
SimpleScreenRecorder image
I tried this code:
QKeyEvent * eve1 = new QKeyEvent (QEvent::KeyPress,Qt::Key_R,Qt::ControlModifier|Qt::ShiftModifier,"r");
qApp->postEvent ((QObject*)this, (QEvent *)eve1);
QKeyEvent * eve2 = new QKeyEvent (QEvent::KeyRelease,Qt::Key_R,Qt::ShiftModifier|Qt::ControlModifier,"r");
qApp->postEvent ((QObject*)this, (QEvent *)eve2);
But this does not work.
I can send key press event to ui->lineEdit but a can't send it to another running application in this case SimpleScreenRecorder.
How can I solve this problem?
Thanks.

void MainWindow::on_pushButton_clicked()
{
system("xdotool key \"control+shift+r\"");
}

Related

WinAppDriver OutLook New Email Elements not found

Trying to mimic (automate) email sending through outlook using WinAppDriver, the "New E-mail" element is recognized and new window opens but on the new Window the "To","CC" etc controls are not recognized.
I suspect the new windows session is not available for the driver.
try {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setPlatform(Platform.WIN10);
//capabilities.setCapability("appTopLevelWindow", "0xBB880A");
capabilities.setCapability("app", "C:\\Program Files\\Microsoft Office\\Office14\\OUTLOOK.exe");
outlookSession = new WindowsDriver(new URL("http://127.0.0.1:4723"), capabilities);
outlookSession.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
} catch (MalformedURLException e) {
e.printStackTrace();
}
newEmail = outlookSession.findElementByName("New E-mail");
System.out.println("newEmail:::::: " + newEmail);
newEmail.click();
outlookSession.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
outlookSession.findElementByName("To").sendKeys("<email>"); (the 'To' element is not recognized.
I think that the problem you are facing is cause by the fact that Outlook will create a new Windows for your new email. That will result in the window not being part of your current session. The best way to address this, is probably creating a desktop session, finding your new window and then attaching a new session and then controlling your new window from there.
Hope this helps.
~Gilles
switchTo().activeElement() didn't work for me so I had to create a new session to interact with the elements on the new email page. Hopefully, this helps others who had the same issue as me
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("app", "Root");
driver = new WindowsDriver<>(new URL("http://127.0.0.1:4723"), capabilities);
You have to write the code for switching the window from outlook to New email.
Thread.Sleep(TimeSpan.FromSeconds(5));
var allWindowHandles1 = driver.WindowHandles;
driver.SwitchTo().Window(allWindowHandles1[0]);
When ever you have new window then you have to switch the control from one window to other.

BluetoothLEAdvertisementWatcher doesn't work

I have Windows 10 Pro, build 10586.494 on HP ZBook G2. When I go to Settings -> Devices -> Bluetooth and switch on Bluetooth, I can see nearby BLE devices (they are custom made BLE devices manufactured by my company).
I want to interact with my BLE devices in Universal Windows application (in Visual Studio 2015). I use this code (it is just a snippet of code)
BluetoothLEAdvertisementWatcher watcher;
//....
watcher = new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active };
watcher.Received += WatcherOnReceived;
watcher.Start();
//....
private void WatcherOnReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs btAdv)
{
}
When I run this application, WatcherOnReceived is never executed (although watcher.Start was executed). Why and how to fix it?
If found a better workaround for this. (I'm using Win 10 1803.)
First, to recap the problem since the original question is not entirely clear about it:
BluetoothLEAdvertisementWatcher works if BLE device is advertising before watcher.Start()
BluetoothLEAdvertisementWatcher does not work if BLE device starts advertising after watcher.Start()
If BluetoothLEAdvertisementWatcher is not working after watcher.Start(), it will begin working when Windows 10 Bluetooth Settings is opened or closed (i.e. the opening or closing of the settings window triggers BluetoothLEAdvertisementWatcher to start working)
So, the workaround I came up with is to keep starting and stopping a second BluetoothLEAdvertisementWatcher in the background to create the same sort of trigger that the Windows Bluetooth Settings window provides.
For example, using a WinForms timer:
...
var timer = new Timer { Interval = 1000 };
timer.Tick += Timer_Tick;
timer.Start();
...
private void Timer_Tick(object sender, EventArgs e)
{
var watcher = new BluetoothLEAdvertisementWatcher();
watcher.Received += (s, a) => { };
watcher.Start();
Task.Delay(500).ContinueWith(_ => watcher.Stop());
}
I have to keep Bluetooth switched on in Settings -> Devices -> Bluetooth in order to receive advertisements in my app.

How to start the app that is associated to the IBackgroundTask I've created in UWP Windows 10

I implemented an IBackgroundTask on Universal Windows 10 and it works like a charm but the problem is that i want to start the app that is associated to that background task if some action occurs. The code is simple:
public sealed class AdvertisementWatcherTask : IBackgroundTask
{
private IBackgroundTaskInstance backgroundTaskInstance;
public void Run(IBackgroundTaskInstance taskInstance)
{
backgroundTaskInstance = taskInstance;
var details = taskInstance.TriggerDetails as BluetoothLEAdvertisementWatcherTriggerDetails;
if (details != null)
{
//Do things
}
}
}
I've seen that you can create a ToastNotification like that:
Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
Windows.Data.Xml.Dom.XmlNodeList elements = toastXml.GetElementsByTagName("text");
foreach (IXmlNode node in elements)
{
node.InnerText = taskInstance.Task.Name+ " remember to uninstall task if not debugging";
}
ToastNotification notification = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(notification);
The notification toast works good. It creates and prompts a notification and if you click it, the app that created this background task starts. This is the behaviour that I want but I want to start the app without having to click any notification. Is there any way to achieve this? Thank you.
TL;DR: I want to start the app that created the background task at some point of the code.
You can not programmatically launch URI or open app from background task. You can however display a reminder or toast notification to let user open your app.

Switch between two windows in selenium webdriver

I am getting error of NoSuchWindowException with this code.I am unable to switch back to old opened window and get back to new window
please review my code and help me.
public void TC_123617()throws InterruptedException {
driver.findElement(By.id("user_login")).sendKeys("akhil");
driver.findElement(By.id("user_pass")).sendKeys("akhil");
driver.findElement(By.id("wp-submit")).click();
Thread.sleep(3000);
driver.findElement(By.cssSelector("#awebsome_oruw-2 > ul")).click();
WebElement userStatus = driver.findElement(By.xpath(".//*[#id='awebsome_oruw-2']/ul/li[11]"));
String parentWindow = driver.getWindowHandle();
driver = new FirefoxDriver();
driver .manage().window().maximize();
driver.get("http://103.16.143.96/incis/wp-login.php");
driver.findElement(By.id("user_login")).sendKeys("manager");
driver.findElement(By.id("user_pass")).sendKeys("manager");
driver.findElement(By.id("wp-submit")).click();
for (String popUpHandle : driver.getWindowHandles()) {
if(!popUpHandle.equals(parentWindow)){
driver.switchTo().window(popUpHandle);
driver.switchTo().window(parentWindow);
}
}
}
You don't need to create a new driver instance if you want to switch between windows using driver.
Save a reference to current window. (so that you can return to perform actions on the window you started from.)
String parentWindow = driver.getWindowHandle();
Next Step, get all the windows and switch to the new window.
List<String> allWindows = driver.getWindowHandles();
for(String curWindow : allWindows){
driver.switchTo().window(curWindow);
}
Now, you can perform any action on the new window, and when done you could close it using
driver.close();
Finally, you can switch back to the parent window to continue your actions using
driver.switchTo().window(parentWindow)

Create a Windows Session from a service via the Win32 API

I have a windows service that can create an executable in the users windows session, via calling the "CreateProcessAsUser" function. This works fine as long as there is a windows session already there. In the case that there isn't one already I'd like to be able to create one programmatically. Is this is possible? Can't seem to find a function to do it.
This isn't quite the solution for the question I asked, but it was the solution that helped achieve what I was trying to achieve by asking this question, if you see what I mean.
Rather than have having a windows services that creates a server session you can configure windows to automatically logon at boot time. This still means someone could accenditally log off, but cures the main reason for sessions disappearing: the server being rebooted. Use the following steps to activate auto-logon:
Press the Windows key + R on your keyboard to launch the “Run” dialog box.
Type regedit and hit enter to open the Registry Editor
Then browse to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon\
Set AutoAdminLogon = 1 (create it if doesn't exist its a string variable)
Set DefaultUserName = your username (create it if doesn't exist its a string variable)
Set DefaultPassword = your password (create it if doesn't exist its a string variable)
Instructions were taken from this post:
http://channel9.msdn.com/Blogs/coolstuff/Tip-Auto-Login-Your-Windows-7-User-Account
You cannot create a new session from a service. Sessions are managed by the OS. New ones get created when users logon interactively.
#Robert, I know this is an old question and that you've already found something that works for you but in my case I was looking for something similar to your original question and I did finally figure it out so I thought I'd share. My solution uses only .NET and a COM reference not the Win32 API mentioned in your title, but I'm guessing that wasn't really a requirement for you.
I've written a simple utility to using the Remote Desktop ActiveX control (COM Reference). If you paste this code into a Class Library you can then call it by simply passing in the server, username, domain, and password and everything is done for you without any other interaction required. Once the method is complete you can then call your "CreateProcessAsUser" Code. I've written this utility in a way so that you could call it every time but initiating an RDP session takes several seconds so for performance sake I'd suggest you write another method to enumerate the sessions and see if your user is logged in and only call this utility when you determine that your user isn't logged in (That's what I did in my actual project). If you feel you need help with that post in the comments and I'll share how I did that but It's not really part of this question so for now I'm leaving it out.
Here's a link back to my question that has a few more requirements/details than this question.
Create Windows Session programmatically from Console or Windows Service
And here's my RDP utility. After you put this code in a class library you can then call it from a console app, winForms app, or from a windows service running on the same machine or from a remote machine.
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using AxMSTSCLib;
namespace Utility.RemoteDesktop
{
public class Client
{
private int LogonErrorCode { get; set; }
public void CreateRdpConnection(string server, string user, string domain, string password)
{
void ProcessTaskThread()
{
var form = new Form();
form.Load += (sender, args) =>
{
var rdpConnection = new AxMSTSCLib.AxMsRdpClient9NotSafeForScripting();
form.Controls.Add(rdpConnection);
rdpConnection.Server = server;
rdpConnection.Domain = domain;
rdpConnection.UserName = user;
rdpConnection.AdvancedSettings9.ClearTextPassword = password;
rdpConnection.AdvancedSettings9.EnableCredSspSupport = true;
if (true)
{
rdpConnection.OnDisconnected += RdpConnectionOnOnDisconnected;
rdpConnection.OnLoginComplete += RdpConnectionOnOnLoginComplete;
rdpConnection.OnLogonError += RdpConnectionOnOnLogonError;
}
rdpConnection.Connect();
rdpConnection.Enabled = false;
rdpConnection.Dock = DockStyle.Fill;
Application.Run(form);
};
form.Show();
}
var rdpClientThread = new Thread(ProcessTaskThread) { IsBackground = true };
rdpClientThread.SetApartmentState(ApartmentState.STA);
rdpClientThread.Start();
while (rdpClientThread.IsAlive)
{
Task.Delay(500).GetAwaiter().GetResult();
}
}
private void RdpConnectionOnOnLogonError(object sender, IMsTscAxEvents_OnLogonErrorEvent e)
{
LogonErrorCode = e.lError;
}
private void RdpConnectionOnOnLoginComplete(object sender, EventArgs e)
{
if (LogonErrorCode == -2)
{
Debug.WriteLine($" ## New Session Detected ##");
Task.Delay(10000).GetAwaiter().GetResult();
}
var rdpSession = (AxMsRdpClient9NotSafeForScripting)sender;
rdpSession.Disconnect();
}
private void RdpConnectionOnOnDisconnected(object sender, IMsTscAxEvents_OnDisconnectedEvent e)
{
Environment.Exit(0);
}
}
}
What about the LogonUser function?
http://winapi.freetechsecrets.com/win32/WIN32LogonUser.htm

Resources