+ Reply to Thread
Results 1 to 6 of 6

Letting user customize the "key" for Onkey

  1. #1
    Registered User
    Join Date
    01-08-2021
    Location
    China, Jiangsu
    MS-Off Ver
    2016
    Posts
    27

    Letting user customize the "key" for Onkey

    Hello,
    I want to let my user to customize which key to trigger my Onkey function.

    Please Login or Register  to view this content.
    the worksheet("KeyBindings") looks like this
    20210311161549.png



    Problem is, I don't expect my user to know how to enter the keys that .Onkey understands (for example, {PGDN}), so I need to have something to get which key the user pressed (and convert into the string that .Onkey understands, if necessary).
    The best method I found on the Internet is KeyPress Event, and I am not sure if there is a good way to convert Ascii from KeyPress to string for Onkey.
    Or are there any better ways?

    Thank you very much.

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,908

    Re: Letting user customize the "key" for Onkey

    Store the KeyCode using the KeyDown event (KeyPress will not trap things like PgDown) and then enclose that value in curly brackets like this:

    Please Login or Register  to view this content.
    Rory

  3. #3
    Registered User
    Join Date
    01-08-2021
    Location
    China, Jiangsu
    MS-Off Ver
    2016
    Posts
    27

    Re: Letting user customize the "key" for Onkey

    Thank you so much.

    And I just realized Onkey can understand "{Keycode}" from KeyDown

  4. #4
    Registered User
    Join Date
    01-08-2021
    Location
    China, Jiangsu
    MS-Off Ver
    2016
    Posts
    27

    Re: Letting user customize the "key" for Onkey

    I just realized that the user will not understand the Integer from Keycode. As shown in the image of my original post, the user should know which key the function is bind to.

    Is there a simple way to convert Keycode Integer to something the user can easily understand? Do I have to put a function to translate every integer?

  5. #5
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,908

    Re: Letting user customize the "key" for Onkey

    You'll need a translation table for any non-character keys like PgDown. Others you should be able to just read the character from the textbox.

  6. #6
    Registered User
    Join Date
    01-08-2021
    Location
    China, Jiangsu
    MS-Off Ver
    2016
    Posts
    27

    Re: Letting user customize the "key" for Onkey

    Many thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. login with "A" user means in List box its should show only "A" user data"
    By krishnaji.B in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-22-2021, 07:28 AM
  2. Replies: 1
    Last Post: 02-22-2021, 07:12 AM
  3. login with "A" user means in List box its should show only "A" user data"
    By krishnaji.B in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-19-2021, 06:01 AM
  4. Replies: 0
    Last Post: 02-19-2021, 05:12 AM
  5. Replies: 1
    Last Post: 02-06-2020, 03:36 AM
  6. Requiring input by user to be either "Economy", "Business" or "Club"
    By cmurda in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2014, 08:57 PM
  7. Replies: 1
    Last Post: 04-05-2006, 09:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1