Consulting

Results 1 to 10 of 10

Thread: Solved: Send to Shift keys to Windows

  1. #1
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location

    Solved: Send to Shift keys to Windows

    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?
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    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?

  3. #3
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hmmm...

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

    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!

    EDITED to clarify shift info!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  4. #4
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    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.
    [VBA]
    Option Explicit
    Private Type OSVERSIONINFO
    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
    Const KEYEVENTF_EXTENDEDKEY = &H1
    Const KEYEVENTF_KEYUP = &H2
    Const VER_PLATFORM_WIN32_NT = 2
    Const VER_PLATFORM_WIN32_WINDOWS = 1

    Sub SetShift()
    Dim o As OSVERSIONINFO
    '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
    keybd_event VK_LSHIFT, &HA0, KEYEVENTF_EXTENDEDKEY Or 0, 0
    keybd_event VK_LSHIFT, &HA0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
    ' keybd_event VK_RSHIFT, &HA1, KEYEVENTF_EXTENDEDKEY Or 0, 0
    ' keybd_event VK_RSHIFT, &HA1, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
    'End If
    End Sub

    [/VBA]

  5. #5
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    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!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  6. #6
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    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.

    [VBA]
    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
    [/VBA]

  7. #7
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Awesome, Tommy, thanks!

    I think I may have a way to test it. I'll give it a shot and let you know!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  8. #8
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I'm here

  9. #9
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    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!

    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.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  10. #10
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Good deal! If there is more I can help with let me know

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •