batch-script for finding shortcut-keys

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
AiroNG
Posts: 46
Joined: 17 Nov 2013 15:00
Location: Germany

batch-script for finding shortcut-keys

#1 Post by AiroNG » 26 Nov 2013 08:07

This thread made me think about a way to use a pure batch-script for finding and displaying all shortcut keys.

The program will create a file where all .lnk / .pif / .url files will be listed (%tmp%\shortcutlist.txt).
Then it will search every file listed for every possible shortcut-key combination
and lists them in a seperate file (%tmp%\shortcutkeys.txt).
That will take quite a while and there will be "false positives".
But those can be tested by pressing the shown key combinations.

Update:
The program searches now for letter-, number-, numpad- and function-keys.
It will do so very slowly. If anyone has an idea how to speed up the search, please let me know.


Code: Select all

:: 
:: batch script for scanning for shortcut keys
::
:: the more shortcuts (.lnk, .pif, .url) there are
:: the longer this program will take to complete
:: the scan. as of now punctuation keys are excluded
::
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

:: creating shortcut list
echo: creating shortcut list...
pushd "%UserProfile%\AppData\Roaming\Microsoft\Windows\Start Menu"
 dir *.lnk *.url *.pif /b /s /a-d >%tmp%\shortcutlist.txt
popd
pushd "%UserProfile%\Desktop"
 dir *.lnk *.url *.pif /b /s /a-d >>%tmp%\shortcutlist.txt
popd
pushd "%AllUsersProfile%\Microsoft\Windows\Start Menu\"
 dir *.lnk *.url *.pif /b /s /a-d >>%tmp%\shortcutlist.txt
popd
echo: scanning for assigned keys... this WILL take a while!
echo: begin of list>%tmp%\shortcuts.txt

:: checking every listed file in %tmp%\shortcutlist.txt
for /f "tokens=*" %%a in (%tmp%\shortcutlist.txt) do (
 for %%x in ( ♠ ♣ ♥ • ) do (
  for %%z in ( A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 p q r s t u v w x y z { ` a b c d e f g h i j k m n o ) do (
   if "%%x"=="♠" set "comb=ctrl + alt + "
   if "%%x"=="♣" set "comb=shift + alt + "
   if "%%x"=="♥" set "comb=ctrl + shift + "
   if "%%x"=="•" set "comb=ctrl + alt + shift + "
   set "key=%%z"
   if "%%z"=="p" set "key=F1"
   if "%%z"=="q" set "key=F2"
   if "%%z"=="r" set "key=F3"
   if "%%z"=="s" set "key=F4"
   if "%%z"=="t" set "key=F5"
   if "%%z"=="u" set "key=F6"
   if "%%z"=="v" set "key=F7"
   if "%%z"=="w" set "key=F8"
   if "%%z"=="x" set "key=F9"
   if "%%z"=="y" set "key=F10"
   if "%%z"=="z" set "key=F11"
   if "%%z"=="{" set "key=F12"
   if "%%z"=="`" set "key=Numpad 0"
   if "%%z"=="a" set "key=Numpad 1"
   if "%%z"=="b" set "key=Numpad 2"
   if "%%z"=="c" set "key=Numpad 3"
   if "%%z"=="d" set "key=Numpad 4"
   if "%%z"=="e" set "key=Numpad 5"
   if "%%z"=="f" set "key=Numpad 6"
   if "%%z"=="g" set "key=Numpad 7"
   if "%%z"=="h" set "key=Numpad 8"
   if "%%z"=="i" set "key=Numpad 9"
   if "%%z"=="j" set "key=Numpad *"
   if "%%z"=="k" set "key=Numpad +"
   if "%%z"=="m" set "key=Numpad -"
   if "%%z"=="n" set "key=Numpad ,"
   if "%%z"=="o" set "key=Numpad /"
   findstr /M %%z%%x %%a 2>nul && echo: %%a  -  !comb! !key!>>%tmp%\shortcutkeys.txt
  )
 )
)
 
echo: scan complete
echo: end of list>>%tmp%\shortcutkeys.txt
start %tmp%\shortcutkeys.txt
goto :eof


the output will be similar to this:

Code: Select all

 D:\cap.lnk  -  ctrl + alt +  P
 D:\casp.url  -  ctrl + alt + shift +  P
 D:\ca1.pif  -  ctrl + alt +  1
 D:\caf1.lnk  -  ctrl + alt +  F1
 D:\canp1.lnk  -  ctrl + alt +  Numpad 1


edit: posted new code, added information in comments, added example output, renamed output files, corrected output sample, corrected small mistake
Last edited by AiroNG on 29 Nov 2013 17:11, edited 5 times in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: batch-script for finding shortcut-keys

#2 Post by foxidrive » 26 Nov 2013 18:14

Function keys and all sorts of punctuation keys can be set as a hot key - is this catering for them?

AiroNG
Posts: 46
Joined: 17 Nov 2013 15:00
Location: Germany

Re: batch-script for finding shortcut-keys

#3 Post by AiroNG » 27 Nov 2013 05:26

foxidrive wrote:Function keys and all sorts of punctuation keys can be set as a hot key - is this catering for them?

Not at the moment, i'm working on that.

While every letter key (q,w,e,etc.) has it's capitalized ascii-counterpart (Q,W,E,etc.),
and numbers from 0 to 9 do have the "correct" ascii code (0=ascii48, 1=ascii49, 2=ascii50, etc.),
the rest of the keyboard works differently: F1 = p (ascii112), Keypad 1 = a (ascii97) and . = ¥ (ascii190)


edit:
i updated my code in the first post. Function keys and numpad keys will now be searched for too.

Post Reply