Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 260
Default Determine Shift Key Press

Hey guys

I want to be able to click CommandButton1 and if it
detects that I was holding the "Shift" key down during the
click, it give me a msgbox saying "Shift Key Pressed".

How do I do this?

Thank you
Todd Huttenstine
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Determine Shift Key Press

Todd

Where? On a sheet? Try this

Dim ShiftKeyPress As Boolean

Private Sub CommandButton1_Click()
If ShiftKeyPress Then
MsgBox "Shift key is pressed"
Else
MsgBox "Shift key is not pressed"
End If

End Sub

Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)

ShiftKeyPress = True
End Sub

Private Sub CommandButton1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)

ShiftKeyPress = False
End Sub

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Todd Huttenstine" wrote in message
...
Hey guys

I want to be able to click CommandButton1 and if it
detects that I was holding the "Shift" key down during the
click, it give me a msgbox saying "Shift Key Pressed".

How do I do this?

Thank you
Todd Huttenstine



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 260
Default Determine Shift Key Press

It works but after I press the shift key and then click,
it always tells me shift key was pressed on all other
clicks even if Shift was not pressed.

-----Original Message-----
Todd

Where? On a sheet? Try this

Dim ShiftKeyPress As Boolean

Private Sub CommandButton1_Click()
If ShiftKeyPress Then
MsgBox "Shift key is pressed"
Else
MsgBox "Shift key is not pressed"
End If

End Sub

Private Sub CommandButton1_KeyDown(ByVal KeyCode As

MSForms.ReturnInteger, _
ByVal Shift As Integer)

ShiftKeyPress = True
End Sub

Private Sub CommandButton1_KeyUp(ByVal KeyCode As

MSForms.ReturnInteger, _
ByVal Shift As Integer)

ShiftKeyPress = False
End Sub

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Todd Huttenstine"

wrote in message
...
Hey guys

I want to be able to click CommandButton1 and if it
detects that I was holding the "Shift" key down during

the
click, it give me a msgbox saying "Shift Key Pressed".

How do I do this?

Thank you
Todd Huttenstine



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 260
Default Determine Shift Key Press

I added the last line to the click event and it works:

Private Sub CommandButton1_Click()
If ShiftKeyPress Then
MsgBox "Shift key is pressed"
Else
MsgBox "Shift key is not pressed"
End If
ShiftKeyPress = False
End Sub

-----Original Message-----
Todd

Where? On a sheet? Try this

Dim ShiftKeyPress As Boolean

Private Sub CommandButton1_Click()
If ShiftKeyPress Then
MsgBox "Shift key is pressed"
Else
MsgBox "Shift key is not pressed"
End If

End Sub

Private Sub CommandButton1_KeyDown(ByVal KeyCode As

MSForms.ReturnInteger, _
ByVal Shift As Integer)

ShiftKeyPress = True
End Sub

Private Sub CommandButton1_KeyUp(ByVal KeyCode As

MSForms.ReturnInteger, _
ByVal Shift As Integer)

ShiftKeyPress = False
End Sub

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Todd Huttenstine"

wrote in message
...
Hey guys

I want to be able to click CommandButton1 and if it
detects that I was holding the "Shift" key down during

the
click, it give me a msgbox saying "Shift Key Pressed".

How do I do this?

Thank you
Todd Huttenstine



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Determine Shift Key Press

Todd

You're right. If you release the Shift key after you click the message box,
it works OK. But if you release it while the message box is in focus, the
KeyUp doesn't fire.

Add

ShiftKeyPress = False

to the end of your click event. Then you will have the problem of the user
holding the shift key for two consecutive clicks. I think if you want this
to be rock solid, you'll need to use the API to hook the keyboard.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Todd Huttenstine" wrote in message
...
It works but after I press the shift key and then click,
it always tells me shift key was pressed on all other
clicks even if Shift was not pressed.

-----Original Message-----
Todd

Where? On a sheet? Try this

Dim ShiftKeyPress As Boolean

Private Sub CommandButton1_Click()
If ShiftKeyPress Then
MsgBox "Shift key is pressed"
Else
MsgBox "Shift key is not pressed"
End If

End Sub

Private Sub CommandButton1_KeyDown(ByVal KeyCode As

MSForms.ReturnInteger, _
ByVal Shift As Integer)

ShiftKeyPress = True
End Sub

Private Sub CommandButton1_KeyUp(ByVal KeyCode As

MSForms.ReturnInteger, _
ByVal Shift As Integer)

ShiftKeyPress = False
End Sub

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Todd Huttenstine"

wrote in message
...
Hey guys

I want to be able to click CommandButton1 and if it
detects that I was holding the "Shift" key down during

the
click, it give me a msgbox saying "Shift Key Pressed".

How do I do this?

Thank you
Todd Huttenstine



.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
After press Shift+Ctrl+Up arrw key it does not select up side Col sudhir Excel Discussion (Misc queries) 0 May 30th 09 08:14 AM
I press upper shift & " BUT I get @ - how can I fix it? Gorilla_Bear Setting up and Configuration of Excel 7 August 5th 08 06:25 PM
When I Press the Enter Key Nothing happens. bigev Excel Discussion (Misc queries) 1 March 1st 06 03:05 PM
Formula to determine shift Liz Excel Worksheet Functions 4 August 15th 05 06:52 AM
test for key press Robert Chapman Excel Programming 6 October 6th 03 05:31 PM


All times are GMT +1. The time now is 10:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"