Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.
Computer Hope forum e-mail issues and down time
0 Members and 1 Guest are viewing this topic.
@echo offREM Create getkey.comecho hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>getkey.comecho hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>getkey.comecho l/QnKE@HB61H.>>getkey.comREM Run getkey.com which...REM ...waits for a keypressgetkey.comREM ASCII value of key is contained in %errorlevel%echo %errorlevel%
The pause would help
@echo offecho hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>getkey.comecho hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>getkey.comecho l/QnKE@HB61H.>>getkey.comecho Wscript.echo Chr^(WScript.Arguments^(0^)^)>CharFromASCII.vbsEcho Please press a keygetkey.comset ascii=%errorlevel%for /f "delims==" %%C in ('cscript //nologo CharFromASCII.vbs %ascii%') do set char=%%Cdel getkey.comdel CharFromASCII.vbsecho You pressed this key: %char%REM Complete with PAUSE at the end...REM Thanks to Jacob.PAUSE
Quote from: Jacob on October 11, 2008, 02:59:59 AMThe pause would help I guess if you run the batch by double clicking it in Windows Explorer, yes, it would help by stopping the command window abruptly closing. I am used to trialling new batch files by having a command window open and typing the batch name at the prompt, to avoid exactly that problem.Also, it strikes me that it might be handy to know the actual character of the key which has been pressed, so I whipped up a simple vbscript to return thatCode: [Select]@echo offecho hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>getkey.comecho hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>getkey.comecho l/QnKE@HB61H.>>getkey.comecho Wscript.echo Chr^(WScript.Arguments^(0^)^)>CharFromASCII.vbsEcho Please press a keygetkey.com&for /f "delims==" %%C in ('cscript //nologo CharFromASCII.vbs %errorlevel%') do set char=%%Cdel getkey.com&del CharFromASCII.vbsecho You pressed this key: %char%REM Complete with PAUSE at the end...REM Thanks to Jacob.PAUSE
@echo offecho hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>getkey.comecho hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>getkey.comecho l/QnKE@HB61H.>>getkey.comecho Wscript.echo Chr^(WScript.Arguments^(0^)^)>CharFromASCII.vbsEcho Please press a keygetkey.com&for /f "delims==" %%C in ('cscript //nologo CharFromASCII.vbs %errorlevel%') do set char=%%Cdel getkey.com&del CharFromASCII.vbsecho You pressed this key: %char%REM Complete with PAUSE at the end...REM Thanks to Jacob.PAUSE
@echo offREM Create getkey.comecho hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>getkey.comecho hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>getkey.comecho l/QnKE@HB61H.>>getkey.comREM Run getkey.com which...REM ...waits for a keypress:rungetkey.comREM ASCII value of key is contained in %errorlevel%If %errorlevel%==97 (echo A)If %errorlevel%==98 (echo B)If %errorlevel%==99 (echo C)If %errorlevel%==100 (echo D)If %errorlevel%==101 (echo E)If %errorlevel%==102 (echo F)If %errorlevel%==103 (echo G)If %errorlevel%==104 (echo H)If %errorlevel%==105 (echo I)If %errorlevel%==106 (echo J)If %errorlevel%==107 (echo K)If %errorlevel%==108 (echo L)If %errorlevel%==109 (echo M)If %errorlevel%==110 (echo N)If %errorlevel%==111 (echo O)If %errorlevel%==112 (echo P)If %errorlevel%==113 (echo Q)If %errorlevel%==114 (echo R)If %errorlevel%==115 (echo S)If %errorlevel%==116 (echo T)If %errorlevel%==117 (echo U)If %errorlevel%==118 (echo V)If %errorlevel%==119 (echo W)If %errorlevel%==120 (echo X)If %errorlevel%==121 (echo Y)If %errorlevel%==122 (echo Z)goto runPAUSE >nul
1. Your code only works for lowercase letters of the alphabet 'a' to 'z'. 2. But you show uppercase letters to the user. ASCII 97 is 'a' not 'A'. The keypress program gives a different code if a key is shifted or if Caps Lock is operative.3. By using this formatif test ( do this)Rather than thisif test do thisYou are adding 2 unnecessary lines for each simple IF test
@echo offREM Create getkey.comecho hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>getkey.comecho hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>getkey.comecho l/QnKE@HB61H.>>getkey.comREM Run getkey.com which...REM ...waits for a keypress:rungetkey.comset key=%errorlevel%REM ASCII value of key is contained in %Key%If %Key%==97 echo a [%Key%]If %Key%==98 echo b [%Key%]If %Key%==99 echo c [%Key%]If %Key%==100 echo d [%Key%]If %Key%==101 echo e [%Key%]If %Key%==102 echo f [%Key%]If %Key%==103 echo g [%Key%]If %Key%==104 echo h [%Key%]If %Key%==105 echo i [%Key%]If %Key%==106 echo j [%Key%]If %Key%==107 echo k [%Key%]If %Key%==108 echo l [%Key%]If %Key%==109 echo m [%Key%]If %Key%==110 echo n [%Key%]If %Key%==111 echo o [%Key%]If %Key%==112 echo p [%Key%]If %Key%==113 echo q [%Key%]If %Key%==114 echo r [%Key%]If %Key%==115 echo s [%Key%]If %Key%==116 echo t [%Key%]If %Key%==117 echo u [%Key%]If %Key%==118 echo v [%Key%]If %Key%==119 echo w [%Key%]If %Key%==120 echo x [%Key%]If %Key%==121 echo y [%Key%]If %Key%==122 echo z [%Key%]::----------------------------------------------------------If %Key%==65 echo A [%Key%]If %Key%==66 echo B [%Key%]If %Key%==67 echo C [%Key%]If %Key%==68 echo D [%Key%]If %Key%==69 echo E [%Key%]If %Key%==70 echo F [%Key%]If %Key%==71 echo G [%Key%]If %Key%==72 echo H [%Key%]If %Key%==73 echo I [%Key%]If %Key%==74 echo J [%Key%]If %Key%==75 echo K [%Key%]If %Key%==76 echo L [%Key%]If %Key%==77 echo M [%Key%]If %Key%==78 echo N [%Key%]If %Key%==79 echo O [%Key%]If %Key%==80 echo P [%Key%]If %Key%==81 echo Q [%Key%]If %Key%==82 echo R [%Key%]If %Key%==83 echo S [%Key%]If %Key%==84 echo T [%Key%]If %Key%==85 echo U [%Key%]If %Key%==86 echo V [%Key%]If %Key%==87 echo W [%Key%]If %Key%==88 echo X [%Key%]If %Key%==89 echo Y [%Key%]If %Key%==90 echo Z [%Key%]::----------------------------------------------------------If %Key%==32 echo SpaceBar [%Key%]::ECHO [%KEY%]goto runPAUSE >nul