View Full Version : Solved: Send to Shift keys to Windows

Ken Puls
08-16-2005, 10:21 AM
Hi everyone,

I have kind of a weird problem that I'm trying to fix here. I have some swipe card readers, and am speculating that every now and then, they seem to turn on the Shift key on the computer keyboard... almost like they're just holding it down. I've bee able to see this with one of my users, who was able to press the shift key a couple of times to bring things back to normal. (This only happens with the card reader attached.)

Now, in itself, this is a minor annoyance, but the issue gets bigger. The user I referred to above is the only user who actually has a keyboard. I have 6 point of sale terminals with swipe readers and touchscreens running on Citrix. (No keyboards at all.)

What I've found on my users PC is that if I hold the shift key down, and swipe a card, instead of returning say 123456, it sends !@#$%^ This is a big issue, since the swipe card is their login id for the system. And without a keyboard, I can't send those two shift keys.

I'd like to write a little VB app to send to shift keys to the Windows interface, as this seemed to fix it in an environment where a keyboard was attached. Unfortunately, I don't know how to make this happen.

I thought about using SendKeys, but opening Excel to do this seems like the wrong way, and SendKeys is VBA specific, I believe. (Plus I couldn't get sendkeys to work for me, either)

Can anyone help me out here?

08-16-2005, 10:35 AM
Hi Ken, I have a sub where I set the caps lock to on using API SetKeyboardState. Otherwise from what I can see we could check the returned swipe and unshift it? Or do the logins have the "shifted" information?

Ken Puls
08-16-2005, 10:43 AM

Dunno, Tommy. This is getting a little out of my usual realm of expertise! :rotlaugh:

Basically what I've got is an application called Jonas that sits at a login screen waiting for these guys to log in. The swipe reader is a PS2 keyboard wedge reader. So they basically swipe their card and it sends 8 characters plus a Carriage Return code.

Issue comes in if something (don't know what) accidentally sets a flag which seems to effectively register that the Shift key is held down. All swipes after that go through as the shifted numbers instead of raw numbers.

My idea was to just have a little VB app on the desktop to send the two shift keys to the OS to unflag the shift key. If they experience the issue, have them return to the desktop (they do have a touchscreen), run the app, and try it again. If I can avoid the hassle of reading every swipe, I'd prefer to do that.

Can the "SetKeyboardState" send those keys, or does it just work with Caps Lock, Num Lock, etc?

I have to be careful, as I am on a shared Wind 2003 Terminal Server using Citrix, which supports about 30 users. I don't want to bugger anything. Having said that, the system is not working for these guys, and I need to find a solution to this issue. This is just an idea to hit one specific problem, and it may not even be the correct one.

IT issues suck sometimes! :mkay

EDITED to clarify shift info!

08-16-2005, 11:08 AM
This should simulate a key press of the left shift key. You may need to do it twice. The Right shift is commented out. I can send a VB app if this works. :)

Option Explicit
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type
' API declarations:
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long
' Constant declarations:
Const VK_CAPITAL = &H14
Const VK_LSHIFT = &HA0
Const VK_RSHIFT = &HA1

Sub SetShift()
'Dim CapsLockState As Boolean
Dim keys(0 To 255) As Byte
o.dwOSVersionInfoSize = Len(o)
GetVersionEx o
GetKeyboardState keys(0)
' CapsLock handling:
'CapsLockState = keys(VK_CAPITAL)
'MsgBox CapsLockState
'If CapsLockState <> True Then 'Turn capslock on
'End If
End Sub

Ken Puls
08-16-2005, 12:40 PM
Heya Tommy!

Nice stuff! Could you VBApp it for me? I have no idea how to convert it.

I unfortunately am at the mercy of my staff reproducing the issue, but would like to have it ready to try if they come up with it again.

Thanks a ton!

08-16-2005, 01:04 PM
Here ya go, The file is an exe I simulate the left shift keypress twice. the program name is ShiftKey. (I know lame name)

btw you should be able to cut and paste the code to excel NP translation not required.

If that does not work the sub below will remove the shift from the string.

Sub RemoveShift(mShift As String)
mShift = LCase(mShift)
mShift = Replace(mShift, "!", "1")
mShift = Replace(mShift, "@", "2")
mShift = Replace(mShift, "#", "3")
mShift = Replace(mShift, "$", "4")
mShift = Replace(mShift, "%", "5")
mShift = Replace(mShift, "^", "6")
mShift = Replace(mShift, "&", "7")
mShift = Replace(mShift, "*", "8")
mShift = Replace(mShift, "(", "9")
mShift = Replace(mShift, ")", "0")
mShift = Replace(mShift, "_", "-")
mShift = Replace(mShift, "+", "=")
mShift = Replace(mShift, "{", "[")
mShift = Replace(mShift, "}", "]")
mShift = Replace(mShift, "|", "\")
mShift = Replace(mShift, ":", ";")
mShift = Replace(mShift, "<", ",")
mShift = Replace(mShift, ">", ".")
mShift = Replace(mShift, "?", "/")
mShift = Replace(mShift, Chr(34), "'")
End Sub

Ken Puls
08-16-2005, 01:11 PM
Awesome, Tommy, thanks!

I think I may have a way to test it. I'll give it a shot and let you know!

08-16-2005, 01:16 PM
I'm here :)

Ken Puls
08-17-2005, 04:29 PM
Sweet deal! Was finally able to recreate the issue on my PC today (no idea what the heck I did though.) Once I finally realized what it was, I just clicked the shortcut to your little app, and fixed! :thumb

So that's test 1 down. I've got it on my server now, just waiting for someone to have the same issue.

Thanks a ton, Tommy! I'm marking this baby solved. :)

08-17-2005, 04:33 PM
Good deal! If there is more I can help with let me know :)