I'm trying to run commands in the terminal and inject "pressing the R key" automatically, avoiding doing it manually.

Just starting out? Need help? Post your questions and find answers here.
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 772
Joined: Fri Dec 04, 2015 9:26 pm

I'm trying to run commands in the terminal and inject "pressing the R key" automatically, avoiding doing it manually.

Post by skinkairewalker »

Is it possible to inject the input of a "r or CTRL+r" key into the terminal automatically, without me having to open the terminal and press it manually?

I also program in Flutter, for mobile devices, however, there is a feature called: hot-reload, and every time I have to keep opening the terminal where the command was executed: flutter run -d chrome or flutter run -d windows, and pressing CTRL+R or just R ...
this completely takes away my focus, is there any way to do this with purebasic automatically with RunProgram or msvcrt->System?

I'm thinking of making a floating Sticky window, and with a "reload" button, and that will solve my problem xD


I'm using the code below, works fine to run debugging via Windows, but hot-reload isn't working.

Code: Select all

ImportC "msvcrt.lib"
  system(str.p-ascii)
EndImport

Global close = 0

;OpenConsole()

system("cd C:\DOCS\MY_PROJECT_PATH\")
Delay(1000)
system("echo ok")
system("flutter run -d windows")

Repeat
  
  system("R") ;- in this line I tried to inject R, but without success...
  
Until close = 1  
  
;system("pause")


screenshot :
Image
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: I'm trying to run commands in the terminal and inject "pressing the R key" automatically, avoiding doing it manually

Post by infratec »

Depending on the program (flutter) you need to send a key press and not a string.

Search for sendinput.
miskox
Enthusiast
Enthusiast
Posts: 107
Joined: Sun Aug 27, 2017 7:37 pm
Location: Slovenia

Re: I'm trying to run commands in the terminal and inject "pressing the R key" automatically, avoiding doing it manually

Post by miskox »

You can try something like this:

Code: Select all

@echo off
echo R|flutter run -d windows
Save this as .cmd/.bat and run from the command prompt to test. Then remove @echo off and change your code.

Saso
Randy Walker
Addict
Addict
Posts: 989
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: I'm trying to run commands in the terminal and inject "pressing the R key" automatically, avoiding doing it manually

Post by Randy Walker »

Don't know if it will help but I found this in some old code from back in my GFA Basic days and may help give you a clue. Need to get window handle into the a1.i variable:

Code: Select all

If a1.i
  //   GYRATIONS below seem unnecessary but,  THEY WORK...
  ~SendMessage(a1.i,WM_SYSKEYDOWN,VK_F4,&21000000)
  ~SendMessage(a1.i,WM_KEYDOWN,VK_F4,&1000000)
  ~SendMessage(a1.i,WM_KEYUP,VK_F4,&81000000)
  ~SendMessage(a1.i,WM_SYSKEYUP,VK_F4,&A1000000)
  Delay(2000)
EndIf
If I recall correctly, those hex values are the ascii character numbers. Do note, you have to tell it key down and key up to be equivalent to the actual keystroke -- same as you hitting the key yourself.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 989
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: I'm trying to run commands in the terminal and inject "pressing the R key" automatically, avoiding doing it manually

Post by Randy Walker »

Nope. I tried and tried, but I cannot send a key to notepad. I know I'm not doing something right with that last parameter, the hex value, but I have no clue what. I had to massage the syntax a little bit. My post above had GFA syntax for sendmessage and & instead of $ for hex number prefix. I was trying to send an uppercase R:

Code: Select all

  BringWindowToTop_(hWin.i)
  SendMessage_(hWin.i,WM_SYSKEYDOWN,VK_RSHIFT,$21000000)
  SendMessage_(hWin.i,WM_KEYDOWN,VK_R,$1000000)
  SendMessage_(hWin.i,WM_KEYUP,VK_R,$81000000)
  SendMessage_(hWin.i,WM_SYSKEYUP,VK_RSHIFT,$A1000000)
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 772
Joined: Fri Dec 04, 2015 9:26 pm

Re: I'm trying to run commands in the terminal and inject "pressing the R key" automatically, avoiding doing it manually

Post by skinkairewalker »

I thank everyone for their help, but I'm trying to make the pb application have full control and connection with the cmd, using only native Process commands in pb. xD
Post Reply