I want to replace a keyboard entry (CTRL PrntSc) with a mouse click (launching a batchfile). I know that there are SEND and SENDKEY codes but have not been able to make the code
Send("^{Printscreen}")
trigger the right effect.
AutoIT and AutoHotKey may be able to do it, but if the above can work, it seems simpler.
Press Keyboard keys using a batch file
deals with a similar question in THIS forum i.e. with making a batchfile first open a program and then send keystrokes to it, but that looks complex and I need guidance in extracting the code for merely sending a batchfile hotkey command.
https://www.donationcoder.com/forum/index.php?topic=25389.0
Suggests the use of NirCMD and AutoIT as well as AutoHotKey and Macro Express. I have experience with the last two - but would need help with all four.
First comment (from Daniel Wisehart)
I'm using Windows 10 - I hope that answers the PLATFORM query. I have already quoted the (ineffective) code of my batchfile. There are NO error messages. However the desired effect of the mouse cursor becoming Greenshot-cross-hairs did not eventuate.
.
Second comment (from Aacini) - thanks for your correction. Replacing "^{Printscreen}" with "^PRTSC" did not make the required difference. The mouse cursor still does not change to a cross-hairs.
I have tried the sample batch file in the 3rd comment (by Hackoo) - which seems extremely complex for just a conversion from a hotkey to a mouse click. It triggers a (blue, NOT black), 'DOS' window saying that "The screen can not be set to the number of lines and columns specified.' Then the text disappears and a little later the window closes.
What is that code ? VB, Visual Basic, VBS, something else ?
Just give a try for this batch file (-_°)
/*
#echo off & cls & color 1E
Mode con Cols=15 lines=5
::Autor Delmar Grande
::http://bbat.forumeiro.com/t248-bat-exe-printscreen-usando-vb-net
::Data Qui 11 Jul 2013
:: Modified by Hackoo on 09/09/2016 to save image with system date
title PrintScreen by Delmar Grande and modified by Hackoo
Rem Just adding a little timeout to organise our screenshot
Timeout /T 4 /Nobreak>nul
findstr "'%skip%VB" "%~f0" > "%tmp%\%~n0.vb"
for /F %%i in ('dir /B /S ^"%WinDir%\Microsoft.NET\Framework\vbc.exe^"') do set "vbc=%%i"
if /i "%vbc%"=="" cls & color 1c & echo This script needs the framework & pause & Exit
cls
%vbc% /nologo /out:"%tmp%\%~n0.exe" "%tmp%\%~n0.vb"
"%tmp%\%~n0.exe"
del "%tmp%\%~n0.vb" >NUL 2>&1
del "%tmp%\%~n0.exe" >NUL 2>&1
exit
*/
Imports System.Windows.Forms 'VB
Module ModulePrintscreen 'VB
Sub Main() 'VB
Dim MaDate As String 'VB
SendKeys.SendWait("{%}({PRTSC})") 'VB
If My.Computer.Clipboard.ContainsImage() Then 'VB
MaDate = Format(Now,"dd-MM-yyyy_hh-mm-ss") 'VB
My.Computer.Clipboard.GetImage.Save(MaDate & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg) 'VB
End If 'VB
End Sub 'VB
End Module 'VB
Related
I made a simple batch script with two diff options, it kinda annoys me that it covers my whole screen although there are 2 lines visible. It would be cool if someone teaches me how to edit the script so that it opens in a smaller (resized window). This is my current script:
#echo off
title Changing Configs..
:main
echo 1 = trade time
echo 2 = grind time
set /p ibo=
if %ibo% == 1 goto trade
if %ibo% == 2 goto grind
:trade
ren "config.yml" "config - nakano.yml"
ren "config - senpai.yml" "config.yml"
pause
exit
:grind
ren "config.yml" "config - senpai.yml"
ren "config - nakano.yml" "config.yml"
pause
exit
I want it to look like this if I run it without resizing it manually
Not sure if there is a way to change the window's size, run mode, or whatever it is called from the batch script itself. It really doesn't matter since you can either control it via shortcut, or just avoid the situation all together.
If you look at the comments on your question, Compo mentioned using a shortcut - this is the most direct answer to your question. Do the following to create desired shortcut:
Create a shortcut by opening windows explorer and navigating to where your batch file is.
Start a drag-n-drop operation by grabbing the batch file with the mouse and moving the mouse off of the file, but DO NOT let go yet. Hold down the CTRL+Shift and the icon you are dragging, or the text under it, will change to indicate you are about to create a link (A.K.A. shortcut). Letting go in the same folder will work, but you may want to move the shortcut later. Alternatively, you could try bringing up a context menu on the batch file by moving the mouse over it and using the secondary click, and then select "create shortcut", which should be found fairly far done on the context menu.
Select the newly created shortcut with the mouse and on the keyboard type Alt+Enter - a properties window should appear. If for some reason that fails. you can use the mouse to bring up a context menu on the newly created shortcut (same way as described in step 2) and select "Properties" (Should be at bottom of context menu).
Go to the "Shortcut" tab in the "Properties" windows, select "Normal windows" from "Run:" section, and click the "OK" button (See image below).
The resulting icon can be moved to the desktop or pinned to the taskbar by dragging to the taskbar.
Or instead, you could rewrite your code so it doesn't ask any questions and just does the job. If you only have 2 choices, why not check which is current, change to the other, and report which one is now the current option?
The following code:
Verifies that copies of both the senpai and nakano configs exist before making any changes.
Checks if the file "Nakano.Active" exist, if so then it does the code to switch to senpai, else it assumes senpai is active and does the code to switch to nakano.
Replaces the current "config.yml" file with the desired configuration.
Deletes the current "{Mode}.Active" file, "Nakano.Active" or "Senpai.Active", as needed.
Creates a new Active file, or flag, to indicate the current mode. That is , creates "Senpai.Active" or "Nakano.Active", as needed.
Echos/reports out what mode it just switch to.
Waits for 2.25 seconds, giving you the time to see what mode it switched to. Change the 225 to the number of centiseconds you want the code to wait before continuing.
Executes EXIT which closes the window.
#ECHO OFF
IF NOT EXIST "config - senpai.yml" GOTO :DoExit
IF NOT EXIST "config - nakano.yml" GOTO :DoExit
IF EXIST Nakano.Active (
COPY /Y "config - senpai.yml" "config.yml" >NUL
DEL Nakano.Active 2>NUL
ECHO;Senpai >Senpai.Active
ECHO;Senpai Mode
) ELSE (
COPY /Y "config - nakano.yml" "config.yml" >NUL
DEL Senpai.Active 2>NUL
ECHO;Nakano >Nakano.Active
ECHO;Nakano Mode
)
REM Pause for 2.25 seconds
SET Centiseconds=225
SET "NOWTIME=%TIME:00.=%"
SET "NOWTIME=%NOWTIME:.=%"
FOR /F "TOKENS=1-3 DELIMS=:" %%G IN ("%NOWTIME::0=:%") DO SET /A "StartCentiseconds=(%%G*60+%%H)*6000+%%I"
SET /A EndCentiseconds=StartCentiseconds+Centiseconds
:GetNow
SET "NOWTIME=%TIME:00.=%"
SET "NOWTIME=%NOWTIME:.=%"
FOR /F "TOKENS=1-3 DELIMS=:" %%G IN ("%NOWTIME::0=:%") DO SET /A "NowCentiseconds=(%%G*60+%%H)*6000+%%I"
IF %NowCentiseconds% LSS %StartCentiseconds% SET /A NowCentiseconds=NowCentiseconds+8640000
IF %NowCentiseconds% LSS %EndCentiseconds% GOTO :GetNow
:DoExit
EXIT
As per comments simply add mode 40,10 or similar at start of file
#echo off & mode 40,10
title Changing Configs..
......
I am trying to create a batch file that plays the beep sound of Bell character. Whenever I try typing Ctrl+G, it triggers the Go To Dialog. I have tried Notepad, Notepad++ and VSCode.
Directly typing echo Ctrl+G in the command line works but I want to run it through a batch file.
If typing Ctrl+G is not possible, is there any other way of playing that beep sound?
There are many ways to do that
In cmd type echo echo ^G >bell.bat (i.e. press Ctrl+G after typing echo echo then redirect the output to a file) and open bell.bat in any text editor and continue editing the file
In Notepad++ you can type 07, select it then open menu Plugins > Converter > HEX -> ASCII
Use Alt Code. In any text editor press Alt+Numpad 7
...
In PowerShell it's even easier. Simply run [char]7 or print it in any echo command and you'll hear a bell. You can also do that from cmd by running powershell -C [char]7 but it's recommended to use PowerShell instead
In PowerShell you also have [console]::Beep() or [console]::Beep(frequency, duration). For example to beep 2 seconds of A440 run
[console]::Beep(440, 2000)
try this:
#echo off
setlocal
::Define a Linefeed variable
(set LF=^
%=-=%
)
for /f eol^=^%LF%%LF%^ delims^= %%A in (
'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x07"'
) do set "BEL=%%A"
echo %BEL%
this will allow to get the BEL character without worrying about editor settings and how the special character will be saved.
"is there any other way of playing that beep sound?"
Why not?
> RunDLL32 User32.dll,MessageBeep
I made a simple LAN chat batch file, and i would like to know if
there is an command that checks if a specific txt file is updated.
The chat history is stored in log.dat and i want to have a sound notification or something like that when theres a new message.
#echo off
title LAN chat reader
call Color.bat
:read
call Color.bat
cls
type log.dat
timeout /t 3 /nobreak >nul
goto read
(im a noob, please tell me if this is possible)
To check the file date/time use for and %%~t prefix:
#echo off
title LAN chat reader
setlocal enableDelayedExpansion
:read
call Color.bat
cls
type log.dat
for %%a in (log.dat) do set filetimesize=%%~tza
:checkupdate
ping -n 1 -w 100 localhost >nul
for %%a in (log.dat) do if "!filetimesize!"=="%%~tza" goto checkupdate
echo updated
goto read
wOxxOm already gave a solution to check for an updated file.
Here is a way to produce a Sound:
copy con bell.txt
Then press the ALT-key enter 007 while keeping ALT pressed, then release the ALT key. ^G should appear on your Screen (= 0x07, which is a Bell), then press Ctrl-Z. This gives you a textfile with lenght = 1 Byte
Type bell.txt
will then beep.
EDIT an easier way to produce bell.txt: on commandline, enter echo ^G>bell.txt (to produce ^G press CTRL-G). This will create a three-byte-file (instead of the one-byte-file with the copy trick) (but that's only a line feed and should not disturb).
How can I start a batch file in full-screen mode? I know that this question was asked before, but it wasn't actually answered.
unfortunately, I don't know reverse engineering, so I cant decompile the code.
Here is something I tested:
#if (#CodeSection == #Batch) #then
#echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
start cmd.exe
%sendkeys% "(%{enter})"
goto :EOF
#end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
The idea is that it starts a cmd window, and (this part of the code %sendkeys% "(%{enter})") is supposed to simulate the user pressing [alt] + [enter]. But it doesn't work.
I wrote a little c# tool to send an alt+enter to the cmd window, but I'm looking for an internal method.
If sendkeys parameter for "Alt-Enter" should be "%{enter}", then this line:
%sendkeys% "(%{enter})"
... should have not parentheses and there is one percent sign missing. Try:
%sendkeys% "%%{enter}"
See the example for "Alt-V" at this post
I made an autoIT script, extremely simple.
Run("cmd.exe")
sleep (1000)
Send("!{enter}")
Unfortunately, this isn't what I want. I was looking for more of an actual command, not some other 3d party program.
:: edit
here: This is a link to the compiled 1 line skiddy script that I made.
Its a command line tool, so all you have to do is type fullscreen in a cmd window to toggle fullscreen mode.
In case you don't know how to use a command line tool, you have to be in the same directory as the file.
I am trying to create a batch file to restart multiple computers from a TXT file. Everything works fine as long as the /c "comment here" parameter has no spaces. If I pass "Testing" as the comment, I get "Testing" in the pop-up for the restart, as expected. If I pass "Testing spaces" as the comment, I still only get "Testing" in the pop-up. With #echo off, I have verified the comment retains the spaces when it is passed to VBS, so I think the problem is that I am running through an "invisible.vbs" script to prevent another CMD window from opening and hanging the original BAT script.
I would like to be able to have a final command run similar to:
shutdown /r /m \\127.0.0.1 /t 120 /c "Your computer will shut down for maintenance tasks in two minutes"
Any help with this would be greatly appreciated!
The essential part of restart.bat:
for /f "tokens=1-3" %%c in (%FilePath%) do WScript /nologo "%windir%\myscripts\invisible.vbs" "shutdown /r /m \\%%c /t %delay% /c %message%"
I have also tried adding extra quotes around %message% with no success:
for /f "tokens=1-3" %%c in (%FilePath%) do WScript /nologo "%windir%\myscripts\invisible.vbs" "shutdown /r /m \\%%c /t %delay% /c "%message%""
The invisible.vbs script (found on StackExchange):
CreateObject("Wscript.Shell").Run "" & WScript.Arguments(0) & "", 0, False
Any help would be greatly appreciated!
EDIT: Using your third method suggested, I am getting a script error:
Script: C:\Windows\myscripts\invisible.vbs
Line: 1
Char: 46
Error: The system cannot find the file specified
Code: 80070002
Source: (null)
EDIT 2: I just tried the first method also, and I now get a vbscript echo pop-up with the correct command that I wish to be sent, but the command is not sent. I am far from a programmer, and the only VBS I have used is stuff I have found online. I do appreciate the help you have offered so far, but I still can't get this to work.
You can not do it. The logic behind the Arguments object in WScript seems to remove quotes.
So, i can think in at least three alternatives
1) The most simple: use another character as an indicator of a quote and replace it with quote in the vbs script
cmd code : cscript myscript.vbs "shutdown /r /m \\%%c /t %delay% /c '%message%'"
vbs code : WScript.CreateObject("WScript.Shell").Run replace(WScript.Arguments(0),"'",""""), 0, False
The only problem with it is at some point, probably, you will need to use the placeholder character as a real character.
2) The most complex: use wmi to retrieve the current process id and from here retrieve the original command line of the script. A lot of code, if interested, here at StackOverflow there are some nice samples.
3) The easy, fast, and unusual. Use environment variables. Save the command into a variable and pass the name of the variable to the script. From it, retrieve the variable contents and use it
cmd code : set "runVar=shutdown /r /m \\%%c /t %delay% /c "%message%""
wscript //nologo "%windir%\myscripts\runInvisible.vbs" runVar
vbs code : With WScript.CreateObject("WScript.Shell") : .Run .ExpandEnvironmentStrings("%" & WScript.Arguments(0) & "%"), 0, False : End With
cmd code or bat code:
wscript //nologo invisible.vbs "hello world" 0
somehow the zero on the end, causes the part between quotes being seen as one argument still