Looking for command-line utility to read keyboard (shift) key state For batch enhancement
#1
Posted 18 August 2006 - 04:09 AM
I'm looking for a (free and small) command-line utility to detect shift key status and returning it in exit code.
Has anyone seen something like that on the net?
When executed from a batch program, it should be possible to check
errorlevel to see if the user was pressing SHIFT for instance.
Regards!
#2
Posted 18 August 2006 - 09:03 PM
mov es ax es mov al [h417] and al 3 mov ah h4c int h21
Return is nonzero if the shift key was held down, otherwise zero.
Quote
(Remove .txt extension from attachment, it doesn't like the .com extension and ZIP'ing a 12-byte file is pointless.)
Attached File(s)
-
SHIFTKEY.COM.txt (12bytes)
Number of downloads: 17
This post has been edited by LLXX: 18 August 2006 - 09:05 PM
#3
Posted 20 August 2006 - 04:27 PM
This is a good startingpoint!
(Now this topic should be moved to programming I guess?)
I have a problem with detecting the state, though.
It seems to behave like a repeating key (like if you press and hold a normal letter) instead of the keypressed state of a shift key.
Tested like this:
@echo off :loop shiftkey& echo %errorlevel%& goto loop
It prints the errorlevel (exitcode from your program) 0's when no shift keys is pressed.
When I push and hold for example the left shift key, it displays '2' once, then 0's for about a second, then more 2's mixed with 0's.
A "real" batch program will do the test at the start, and might likely miss the exact times when the key is detected.
Nevertheless I think what you suggest is the best way to do it (a small asm code)
I guess it should test maybe other bits in the AND statement or another address, but knowing it will take me some time to test and read some, I wanted to thank you at once for this way of doing it!
Cheers LLXX!
#4
Posted 20 August 2006 - 10:36 PM
It only looks like it's repeating because XP's DOS emulation is awful - the state of the shift key is being reported erratically.
I tried with a similar batch file under Win98 and it works perfectly fine.
@echo off :loop shiftkey if errorlevel 0 set errorlev=0 if errorlevel 1 set errorlev=1 if errorlevel 2 set errorlev=2 echo %errorlev% goto loop
Maybe an equivalent Win32 program might work better, but then again, it is difficult to get realtime key states in multitasking OSs anyway.
If you want, I can write the Win32 program.
#5
Posted 21 August 2006 - 04:47 PM
Now TESTED on NT4 server, same result! (So it's not only XP, maybe it's a problem with the 16 bit subsystem or something and I guess Win32 code will work better.)
Haven't touched asm since 386, so I'm in a little over my head here, to say the least!
(This problem explains why I had such a hard time finding compiled code, only script examples in VB6 and so on...)
If you're in the mood it would be very interesting to see if the Win32 approach could work!
But if it turns out to be a lot of work, or small hope of success, please don't!.....
#6
Posted 22 August 2006 - 11:32 AM
http://www.mirkes.de...eware/batch.php
a bunch of batch miniapps for win32/nt/2000/xp, including:
Quote
(untested)
jaclaz
#7
Posted 22 August 2006 - 03:21 PM
Markus' program checks out OK in XP (and probably others), is 29 Kb, GNU GPL freeware.
Supports a lot of key combinations too, not only shift key, and realtime (fast enough for a batch program anyway).
It detects shift key state even if the user is in another program (expected of course).
I will test the multiuser performance with remote desktop to see if it detects only the console keys when run by a remote user, or if all users input is detected, but I have a feeling the OS handles it.
It's a Win32 program made in delphi. (It might work in Win9x, but I guess it needs the 32bit subsystem installed first.)
@LLXX:
The tiny machine code was very, very neat, but I think this is allso what I was looking for and more!
Thanks for your effort and hope this noob haven't wasted too much of your time...
Cheers jaclaz and LLXX!
This post has been edited by aquarius: 22 August 2006 - 03:49 PM
#8
Posted 22 August 2006 - 06:04 PM
Well, whatever works for you...
...and by the way, I didn't really spend much more than a few minutes on that last program.
This post has been edited by LLXX: 22 August 2006 - 06:05 PM
#10
Posted 28 August 2006 - 03:15 AM
I promised to check out the keyboard state in a multiuser environment, i.e. with several sessions running. Only tested shift key state. Remote PC was Windows 2000 SP4
Tested for
VK_SHIFT (Any shift key, left or right)
VK_LSHIFT (Left shift key)
VK_RSHIFT (Right shift key)
Citrix on NT4 and Remote Desktop on Windows Server 2003:
Remote users VK_SHIFT, VK_LSHIFT and VK_RSHIFT works, and no "leak" from the console or other remote sessions.
Netmeeting Remote Desktop: (W2K/XP)
(Which is not very multiuser, it just takes over console and disables local input)
Remote user shift is detected (VK_SHIFT), but it does not detect the difference between the Right or Left shift keys in this scenario, i.e. a test for VK_LSHIFT or VK_RSHIFT would not work.
TightVNC: (W2K Server)
Same as Netmeeting. You can enable local input in VNC, in which case both remote and local user is detected, as should be expected.
Cheers!



Help
Back to top









