Page 1 of 1

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

Posted: Wed Feb 19, 2025 5:23 am
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

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

Posted: Wed Feb 19, 2025 7:56 am
by infratec
Depending on the program (flutter) you need to send a key press and not a string.

Search for sendinput.

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

Posted: Wed Feb 19, 2025 7:01 pm
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

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

Posted: Thu Feb 20, 2025 12:03 am
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.

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

Posted: Thu Feb 20, 2025 3:13 am
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)

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

Posted: Thu Feb 20, 2025 3:45 am
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