Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    detect keyboard inputs

    I have an application that where i need to catch all user input (and disable it !) i am lost as to how i should catch the esc key, the windows 'start' key, the delete key and several others that do not have a direct ascii value. Does anyone have any ideas please?
    The whole idea is that the main form in the application should replace and take over from the windows desktop so i need to bullet proof the app from hacking. the software will be in our company's public access areas and will be used (abused) by all sorts of users.

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect keyboard inputs

    You may want to exploer the Windows API function: keyb_event

    If you have little experience with API calls, you might find this helpful:

    <A target="_blank" HREF=http://www.allapi.net>http://www.allapi.net</A>
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect keyboard inputs

    You can trap the Esc and Ctrl+break keys with

    Application.EnableCancelKey = wdCancelDisabled
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect keyboard inputs

    what an excellent site <A target="_blank" HREF=http://www.allapi.net>http://www.allapi.net</A>
    i hope that it will do the bizz but it may take me some time to read through all of the info.
    thanks <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect keyboard inputs

    They do nice work, huh?

    Did you download the API-Guide? Wait till you take a look at that. Demistifies the entire Windows API. The examples are priceless.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect keyboard inputs

    too much , too soon.
    where does the line
    Application.EnableCancelKey = wdCancelDisabled
    go ?
    Do i need to declare the heyb_event dohicky first ?
    i saw a post on the forum somewhere where some referred to a variable beginning with wd... what is special about these ?

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect keyboard inputs

    wd's aren't variable, they're constants. Lookup the enablecancekey in the vba help. That'll get you straight on that one. That's strictly a VBA command, so you don't need the API for that one.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  8. #8
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect keyboard inputs

    looks like the wheels are about to fall off then, i'm programming in VB6!
    is there any equivalent ?
    application.enablecancelkey is not recognized either !!!
    mayday mayday !!

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect keyboard inputs

    Stick with the API then. You should be able to trap any key with that keyboard function.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  10. #10
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect keyboard inputs

    Hi,

    In VB, you can trap many key strokes by the KeyDown event attached to exach input box. You would want to make this a common routine:

    <pre>Private Sub txtGivenName1_KeyDown(KeyCode As Integer, Shift As Integer)
    Debug.Print KeyCode
    Select Case KeyCode
    ' 27 is escape, 46 is delete
    Case 27, 46
    Exit Sub
    Case Else
    End Select
    End Sub
    </pre>


    You can't trap the escape key if there's a button with the "Cancel" property set to true, or the enter key if the default property is set. It doesn't trap the tab key. t didn't trap "Alt + F4" for me, but I suspect I can disable the close and trap that.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  11. #11
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: detect keyboard inputs

    In VBA (Application.OnKey "%{F4}", "" disables the Alt-F4 keypress, and I am sure it would be available in VB.

    Worth checking out,

    Andrew C

  12. #12
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: detect keyboard inputs

    It appears that Excel is the only Office app that makes the OnKey method available (hey - not fair! <g>)

  13. #13
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: detect keyboard inputs

    You might want to search around for whether someone offers a "kiosk" add-in for MS Office or the OS. Otherwise, it sounds as though you might end up doing a lot of low-level programming.

  14. #14
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: detect keyboard inputs

    You can use the KeyDown event in VB and test the KeyCode against the vbKey constants like vbKeyEscape, then handle them accordingly. I find it much easier to use the built-in VB constants than to remember the ascii value of the keys. Look them up in the Object Browser to get the list. These will also work in the Office apps, and I use them all the time in Access, which is my primary development environment.
    Charlotte

  15. #15
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: detect keyboard inputs

    OK, things are progressing, many thanks to all above. I cannot, however, locate a way of identifying the 'windows logo' key - the one that brings up the start menu.
    Also, the keys action seems to be processed before the key_down event catches it, alt + c , alt + F4 etc.
    Any ideas ?

Page 1 of 2 12 LastLast

Posting Permissions

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