Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-23-2015, 06:52 PM
DariusCode DariusCode is offline Show Key Combination Pressed by User Mac OS X Show Key Combination Pressed by User Office for Mac 2011
Novice
Show Key Combination Pressed by User
 
Join Date: Nov 2015
Posts: 2
DariusCode is on a distinguished road
Default Show Key Combination Pressed by User

I need the code that would emulate what happens when you click in the edit box across from "Press new keyboard shortcut in Customize Toolbars & Menus > Customize Keyboard (when Keyboard... button is pressed). This is the dialog box in which user assigns a key combination to a macro.

I need to find out exactly what key combination user has pressed inside a text box in a dialog box and show it exactly like MS Word does in Customize Keyboard dialog box., e.g. Command+Control+Shift+A (I'm a Mac user).

I'm using TextBox_KeyUp() in a dialog box but for some reason it doesn't register the Option key or perhaps I don't know what the Shift value for the option is key! The MS Words key in their Customize Keyboard dialog works perfectly.



All help is appreciated.
Reply With Quote
  #2  
Old 11-23-2015, 08:42 PM
Guessed's Avatar
Guessed Guessed is offline Show Key Combination Pressed by User Windows 7 32bit Show Key Combination Pressed by User Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Windows keyboards don't generally have an option key so that might explain why you can't find out if it has been pressed.

You might like to look at some resources where VBA is used to investigate key states
eg
http://www.cpearson.com/excel/keytest.aspx
https://msdn.microsoft.com/en-us/lib...(v=vs.60).aspx
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 11-24-2015, 07:21 AM
DariusCode DariusCode is offline Show Key Combination Pressed by User Mac OS X Show Key Combination Pressed by User Office for Mac 2011
Novice
Show Key Combination Pressed by User
 
Join Date: Nov 2015
Posts: 2
DariusCode is on a distinguished road
Default

I already have all of this rudimentary knowledge about key states. If you read my thread carefully you would know that I'm a Mac user and I specifically stated that the MS Word dialog box DOES indeed detect the Option key on the Mac keyboard. I was wondering if perhaps an MS insider would have the code for the Customize Keyboard key detection code...
Reply With Quote
  #4  
Old 11-24-2015, 03:40 PM
macropod's Avatar
macropod macropod is offline Show Key Combination Pressed by User Windows 7 64bit Show Key Combination Pressed by User Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

In Windows, you might use userform code like:
Code:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim strMask As String, StrKey As String
Select Case Shift
  Case 1: strMask = "Shift+"
  Case 2: strMask = "Ctrl+"
  Case 3: strMask = "Ctrl+Shift+"
  Case 4: strMask = "Alt+"
  Case 5: strMask = "Alt+Shift+"
  Case 6: strMask = "Ctrl+Alt+"
  Case 7: strMask = "Ctrl+Alt+Shift+"
  Case Else: strMask = ""
End Select
Select Case KeyCode
  Case vbKeyF1: StrKey = "F1"
  Case vbKeyF2: StrKey = "F2"
  Case vbKeyF3: StrKey = "F3"
  Case vbKeyF4: StrKey = "F4"
  Case vbKeyF5: StrKey = "F5"
  Case vbKeyF6: StrKey = "F6"
  Case vbKeyF7: StrKey = "F7"
  Case vbKeyF8: StrKey = "F8"
  Case vbKeyF9: StrKey = "F9"
  Case vbKeyF10: StrKey = "F10"
  Case vbKeyF11: StrKey = "F11"
  Case vbKeyF12: StrKey = "F12"
  Case vbKeyHome: StrKey = "Home"
  Case vbKeyEnd: StrKey = "End"
  Case vbKeyPageUp: StrKey = "PageUp"
  Case vbKeyPageDown: StrKey = "PageDown"
End Select
TextBox1.Text = strMask & StrKey
End Sub
The KeyCode Select Case statement above contains only a partial KeyCode listing - see the VBA help file for the full KeyCode listing.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 11-24-2015, 04:36 PM
Guessed's Avatar
Guessed Guessed is offline Show Key Combination Pressed by User Windows 7 32bit Show Key Combination Pressed by User Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The KeyDown event looks like it makes a lot more sense than the KeyUp event.

I had a little play with Paul's code to add CaseElse's that would reveal the integer values of other keys which may be pressed. I note that combinations can give different results depending on the order of the key presses (eg Ctrl then Alt returns a different result to Alt then Ctrl).
The first Case Else should be amended as follows to reveal the integer value of the modifiers
Case Else: strMask = Shift & "+"

You can then add a CaseElse to the second select
Case Else: StrKey = KeyCode
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Tags
key bindings



Similar Threads
Thread Thread Starter Forum Replies Last Post
Show Key Combination Pressed by User Autofill form in word in combination with VBA nouki Word VBA 9 10-14-2015 01:20 PM
Show Key Combination Pressed by User Preventing text from moving down in a form when enter is pressed tgeary00 Word 2 10-29-2013 06:51 PM
Show Key Combination Pressed by User tcp-t F3 key combination used in template revans611 Word 1 11-29-2010 11:57 AM
Help with Combination function sanasath Excel 0 12-13-2005 07:24 AM
Outlook problem - Open Other User’s Folder doesn’t show Sent imported_bankboysb Outlook 0 12-12-2005 11:41 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft