aquarius Posted August 18, 2006 Posted August 18, 2006 Hi!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!
LLXX Posted August 19, 2006 Posted August 19, 2006 (edited) Why don't I just write one for you right now? mov es axesmov al [h417]and al 3mov ah h4cint h21Return is nonzero if the shift key was held down, otherwise zero.(free and small)12 little bytes. I don't think it can get any smaller than that (Remove .txt extension from attachment, it doesn't like the .com extension and ZIP'ing a 12-byte file is pointless.)SHIFTKEY.COM.txt Edited August 19, 2006 by LLXX
aquarius Posted August 20, 2006 Author Posted August 20, 2006 Very good, and really small! 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:loopshiftkey& echo %errorlevel%& goto loopIt 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!
LLXX Posted August 21, 2006 Posted August 21, 2006 The shift key does not repeat. And, according to the PC Technical Reference, 0417 is the only address with the state of the shift keys (lower 2 bits). The other bits there are for Ctrl, Alt, ScrollLock, NumLock, CapsLock, etc.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:loopshiftkeyif errorlevel 0 set errorlev=0if errorlevel 1 set errorlev=1if errorlevel 2 set errorlev=2echo %errorlev%goto loopMaybe 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.
aquarius Posted August 21, 2006 Author Posted August 21, 2006 Yes, exactly, the shift keys doesn't repeat, but the test pattern on both Windows 2000 SP4 and XP SP2 matched the typical "rythm" of repeating keys .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!.....
jaclaz Posted August 22, 2006 Posted August 22, 2006 Maybe I am late, but check this:http://www.mirkes.de/en/freeware/batch.phpa bunch of batch miniapps for win32/nt/2000/xp, including:iskeydown checks if one or more keys are pressed (also control, shift etc.) and sets the errorlevel(untested)jaclaz
aquarius Posted August 22, 2006 Author Posted August 22, 2006 (edited) Seems to fit the bill for me, jaclaz 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! Edited August 22, 2006 by aquarius
LLXX Posted August 23, 2006 Posted August 23, 2006 (edited) A 29Kb "miniapp"?? Well, whatever works for you......and by the way, I didn't really spend much more than a few minutes on that last program. Edited August 23, 2006 by LLXX
aquarius Posted August 28, 2006 Author Posted August 28, 2006 Hi!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 SP4Tested 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!
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now