Consulting

Results 1 to 2 of 2

Thread: [VBA] How to trigger a macro with a letter key without "Ctrl"

  1. #1

    [VBA] How to trigger a macro with a letter key without "Ctrl"

    Hello,


    So the problem is, I am creating a simple game in Excel&VBA with two players, each player needs to control four keys. For the first player, I used the four direction keys and Application.OnKey function, like this:


    Sub DeclareKeys()
    Application.OnKey "{UP}", "Move_up"
    Application.OnKey "{DOWN}", "Move_down"
    Application.OnKey "{LEFT}", "Move_left"
    Application.OnKey "{RIGHT}", "Move_right"
    End Sub


    But for the second player, I have to use those letter keys like "w, s, a, d" to trigger macros, but I cannot use Application.OnKey for those keys. I can also assign shortcut using "Ctrl + w", "Ctrl + d" ..., but that is not user-friendly for the player, and also the input from the direction keys combining the "Ctrl" will have some other negative effects.


    So basically, how to trigger a macro with only a letter key, without "Ctrl" or anything else?


    By the way, if we remove the {} like this: Application.OnKey "a", "some_proc" , it did not work, and when I click one the keyboard, it just makes what I type appear somewhere on the datasheet, and the Macro cannot be triggered.


    Thank you so much!

  2. #2
    Problem solved, using ASCII code would do.

Tags for this Thread

Posting Permissions

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