Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How I can use the repo to type some command in a Python environment? #6

Open
zydjohnHotmail opened this issue Mar 30, 2022 · 22 comments

Comments

@zydjohnHotmail
Copy link

Hello:
Now, I have to run some Python command in a very specific Python environment.
To launch this environment is rather complicated, but it is way more complicated to set it up.
However, after setting up the environment, I only need to run some Python command in the environment.
But I want to use the repo to run some command, for the simplest one is: dir
However, I can’t find which automation item I can use to sendkeys like: dir.
The following is my C# code:

using System;
using System.Threading.Tasks;
using UIDeskAutomationLib;

namespace RunCondaStyleGAN3Test
{
public class Program
{

static async Task Main(string[] args)
{
await Task.Delay(10000);
int return_code = 0;
if (args.Length == 0)
{
Console.WriteLine("Please enter at least one command");
return -1;
}
else
{
Engine engine = new Engine();
UIDA_Document text_doc =
engine.GetTopLevel("Anaconda Prompt (Anaconda3)").Document("Text Area");
text_doc.SendKeys("dir");
}
Console.WriteLine("Done");
return return_code;
}
}
}

However, my code didn’t work.
Please refer to the Spy screenshot and let me know how I can run a simple command, like “dir”
Thanks,
UISpyFindCondaEnvironment

@ddeltasolutions
Copy link
Owner

ddeltasolutions commented Mar 30, 2022 via email

@zydjohnHotmail
Copy link
Author

Hello:
Thanks for your reply, I have now changed my code, so it looks like this:
static async Task Main(string[] args)
{
await Task.Delay(10000);
int return_code = 0;
if (args.Length == 0)
{
Console.WriteLine("Please enter at least one command");
return -1;
}
else
{
Engine engine = new Engine();
UIDA_Window type_window = engine.GetTopLevel("Anaconda Prompt*");
type_window.SendKeys("dir");
type_window.KeyPress(VirtualKeys.Enter);
}
Console.WriteLine("Done");
return return_code;
}
But it didn't work. I waited, the C# program finished without any error, but the command "dir" did NOT appear on the screen.
See the picture.
Please advise!
UISpyFindCondaEnvironmentNOK

@ddeltasolutions
Copy link
Owner

ddeltasolutions commented Mar 31, 2022 via email

@zydjohnHotmail
Copy link
Author

Hello:
You have to install python (my version is 3.9.7) in Windows 10.
Then install anaconda (my version is 2021.11).
https://www.anaconda.com/download/#windows
Then launch Anaconda Prompt (Anaconda3) from windows 10.
In the command line (Anaconda Prompt), type the following command:
(base) C:\Users\John> python -m venv C:/Pytorch/StyleGan3
Then go to the created folder:
(base) C:\Users\John>cd C:\Pytorch\StyleGan3\Scripts
Then activate the python environment:
(base) C:\Pytorch\StyleGan3\Scripts>activate
Then the command line will have a prefix, like the following
(stylegan3) C:\Pytorch\StyleGan3\Scripts>
Here is the environment, I need to type command, like: "dir".
This part is not difficult!

@ddeltasolutions
Copy link
Owner

ddeltasolutions commented Mar 31, 2022 via email

@ddeltasolutions
Copy link
Owner

ddeltasolutions commented Apr 1, 2022 via email

@zydjohnHotmail
Copy link
Author

Hello:
I have tried the both ways:
static async Task Main(string[] args)
{
await Task.Delay(10000);
int return_code = 0;
if (args.Length == 0)
{
Console.WriteLine("Please enter at least one command");
return -1;
}
else
{
Engine engine = new Engine();
UIDA_Window type_window = engine.GetTopLevel("Anaconda Prompt*");
type_window.BringToForeground();
engine.Sleep(1000);
type_window.KeyPress(VirtualKeys.D);
type_window.KeyPress(VirtualKeys.I);
type_window.KeyPress(VirtualKeys.R);
type_window.KeyPress(VirtualKeys.Enter);
//type_window.SendKeys("dir");
type_window.KeyPress(VirtualKeys.Enter);
}
Console.WriteLine("Done");
return return_code;
}

But none of them worked.
Please advise!
If you can set up such environment, you can try and let me know which one works in your environment.
Thanks,

@ddeltasolutions
Copy link
Owner

ddeltasolutions commented Apr 1, 2022 via email

@zydjohnHotmail
Copy link
Author

Hello:
This I don't know, when I run my code, I simply click on the command prompt window, so it is already in foreground.
But if I don't click on the command prompt, the command prompt did NOT come to foreground.
So, I don't think the code works.
The picture shows when I clicked on command prompt, the same image when I didn't click on command prompt.
UISpyBring2Foreground

@ddeltasolutions
Copy link
Owner

ddeltasolutions commented Apr 2, 2022 via email

@zydjohnHotmail
Copy link
Author

Hello:
I changed my code, so it looks like this:
static async Task Main(string[] args)
{
await Task.Delay(10000);
int return_code = 0;
if (args.Length == 0)
{
Console.WriteLine("Please enter at least one command");
return -1;
}
else
{
Engine engine = new Engine();
UIDA_Window type_window = engine.GetTopLevel("Anaconda Prompt*");
type_window.BringToForeground();
engine.Sleep(1000);
type_window.Click();
type_window.SendKeys("dir");
type_window.KeyPress(VirtualKeys.Enter);
}
Console.WriteLine("Done");
return return_code;
}

But it didn't work.
Please advise!

@ddeltasolutions
Copy link
Owner

ddeltasolutions commented Apr 2, 2022 via email

@zydjohnHotmail
Copy link
Author

Hello:
I don't have Windows 7. But I think you can install Python 2, and Aanaconda 3. Then it should be OK.
But I suggest that you use Windows 10, as Windows 7 is already out of support for more than 2 years.

@ddeltasolutions
Copy link
Owner

ddeltasolutions commented Oct 11, 2022 via email

@ddeltasolutions
Copy link
Owner

ddeltasolutions commented Oct 11, 2022 via email

@ddeltasolutions
Copy link
Owner

ddeltasolutions commented Oct 11, 2022 via email

@zydjohnHotmail
Copy link
Author

Hello:
What Team Viewer you are using, which version?
By the way, I am using Windows 10, you are using Windows 7.
There could be some kind of issues.
Please advise,

@ddeltasolutions
Copy link
Owner

ddeltasolutions commented Oct 11, 2022 via email

@zydjohnHotmail
Copy link
Author

Hello:
I have just installed the same version for Window 10.
We can try to have a session later on.
What information is necessary for one session?

@ddeltasolutions
Copy link
Owner

ddeltasolutions commented Oct 11, 2022 via email

@zydjohnHotmail
Copy link
Author

Hello:
I think the time is OK, but I didn't realize that you are talking about old issue with Python, which I decied to give up, as Python is not good to run for Windows 10, too many packages dependencies. However, I still want to use the SPY tools to automate export public channel contents with Telegram desktop.
If you know how to do this via SPY tools, let me know.
Thanks,

@ddeltasolutions
Copy link
Owner

ddeltasolutions commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants