Catching Control, Shift Key and Alt Key Presses and Releases
-
I have been handed an assignment: update a legacy "window" application. The UI must work the same to avoid user re-training costs. The source code is lost/unavailable. (I suspect it was written by a consultant who did not leave the source code. :( ) This legacy code will not run on Win7 or Win10. (Now you see why it must be updated immediately.. :) ) My problem is that the original author "caught" the Shift, Control and Alt keys to select which data frame to display. If none of the three are pressed and held, the most common data is displayed. If the Shift key is pressed and held, the demographics data is displayed. You get the picture. None of these data frames have any interactive controls. The KeyUp, KeyPress, and KeyDown events are not being caught when these keys are pressed:
Private Sub ucDisplay\_KeyUp(sender As Object, \_ e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp Stop End Sub
Any suggestions on how to catch these events? Can someone point me to a useful reference? Thank you.
__________________ Lord, grant me the serenity to accept that there are some things I just can’t keep up with, the determination to keep up with the things I must keep up with, and the wisdom to find a good RSS feed from someone who keeps up with what I’d like to, but just don’t have the damn bandwidth to handle right now. © 2009, Rex Hammock
-
I have been handed an assignment: update a legacy "window" application. The UI must work the same to avoid user re-training costs. The source code is lost/unavailable. (I suspect it was written by a consultant who did not leave the source code. :( ) This legacy code will not run on Win7 or Win10. (Now you see why it must be updated immediately.. :) ) My problem is that the original author "caught" the Shift, Control and Alt keys to select which data frame to display. If none of the three are pressed and held, the most common data is displayed. If the Shift key is pressed and held, the demographics data is displayed. You get the picture. None of these data frames have any interactive controls. The KeyUp, KeyPress, and KeyDown events are not being caught when these keys are pressed:
Private Sub ucDisplay\_KeyUp(sender As Object, \_ e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp Stop End Sub
Any suggestions on how to catch these events? Can someone point me to a useful reference? Thank you.
__________________ Lord, grant me the serenity to accept that there are some things I just can’t keep up with, the determination to keep up with the things I must keep up with, and the wisdom to find a good RSS feed from someone who keeps up with what I’d like to, but just don’t have the damn bandwidth to handle right now. © 2009, Rex Hammock
Private Shiftdown As Boolean = False
Private altdown As Boolean = False
Private cntrldown As Boolean = False
Private Sub ucDisplay_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
Select Case e.KeyCode
Case Keys.ShiftKey
Shiftdown = False
Case Keys.Menu
altdown = False
Case Keys.ControlKey
cntrldown = False
End Select
End Sub
Private Sub ucDisplay_Keydown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.ShiftKey
Shiftdown = True
Case Keys.Menu
altdown = True
Case Keys.ControlKey
cntrldown = True
End SelectIf Shiftdown AndAlso altdown AndAlso cntrldown Then 'do anything() End If End Sub
-
I have been handed an assignment: update a legacy "window" application. The UI must work the same to avoid user re-training costs. The source code is lost/unavailable. (I suspect it was written by a consultant who did not leave the source code. :( ) This legacy code will not run on Win7 or Win10. (Now you see why it must be updated immediately.. :) ) My problem is that the original author "caught" the Shift, Control and Alt keys to select which data frame to display. If none of the three are pressed and held, the most common data is displayed. If the Shift key is pressed and held, the demographics data is displayed. You get the picture. None of these data frames have any interactive controls. The KeyUp, KeyPress, and KeyDown events are not being caught when these keys are pressed:
Private Sub ucDisplay\_KeyUp(sender As Object, \_ e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp Stop End Sub
Any suggestions on how to catch these events? Can someone point me to a useful reference? Thank you.
__________________ Lord, grant me the serenity to accept that there are some things I just can’t keep up with, the determination to keep up with the things I must keep up with, and the wisdom to find a good RSS feed from someone who keeps up with what I’d like to, but just don’t have the damn bandwidth to handle right now. © 2009, Rex Hammock
The
KeyUp
event only fires when the key is released. It sounds like you want to handle theKeyDown
event instead.Jalapeno Bob wrote:
The source code is lost/unavailable.
Is it a .NET application? If so, and if the consultant didn't use an obfuscator, you might be able to use a decompiler to see what the code is doing. It won't give you a perfect copy of the original source, but it might help. Free .NET decompiler :: JetBrains dotPeek[^] JustDecompile .NET Assembly Decompiler & Browser - Telerik[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
The
KeyUp
event only fires when the key is released. It sounds like you want to handle theKeyDown
event instead.Jalapeno Bob wrote:
The source code is lost/unavailable.
Is it a .NET application? If so, and if the consultant didn't use an obfuscator, you might be able to use a decompiler to see what the code is doing. It won't give you a perfect copy of the original source, but it might help. Free .NET decompiler :: JetBrains dotPeek[^] JustDecompile .NET Assembly Decompiler & Browser - Telerik[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Great Idea!!! Except: Visual Studio shows Intel 80x86 assembly language, not CLR Intermediate language. No symbol table. Just one .exe file. Last compiled in 2001, probably for Win98. Like I said "Legacy code"
__________________ Lord, grant me the serenity to accept that there are some things I just can’t keep up with, the determination to keep up with the things I must keep up with, and the wisdom to find a good RSS feed from someone who keeps up with what I’d like to, but just don’t have the damn bandwidth to handle right now. © 2009, Rex Hammock