1

I am working on a piece of software where we need a calibration form that we want available for the install team to use to calibrate a camera.

It is also useful to have this screen available to customers should they need to calibrate in the future.

However due to the fact that it exposes some pretty low level and technical configurations, we do not want the customers accessing this form if it can be avoided as they can and WILL break something which we will then have to fix.

Therefore I have been asked to show this form upon a combination of keys which consists of the Ctrl key held down whilst typing a word. (much like old pc cheats)

my problem is that I know how to intercept a simple key press with a modifier (eg. ctrl + A) but not a typed word with a modifier.

if someone could enlighten me as to how best to achieve such a function I would be most grateful.

I am using Visual Studio 2012 with VB.net in a windows forms environment

Steven Wood
  • 2,675
  • 3
  • 26
  • 51
  • why not something more straightforward like a password entry which are burned after they are used; maybe they have to call and get the next PW so why they want to do this can be validated as legit. the problem with a cheat code is that once they know it, they know it forever. – Ňɏssa Pøngjǣrdenlarp Jun 09 '14 at 14:46
  • I know I offered a smilar course but it has been mandated to do it this way :-( – Steven Wood Jun 09 '14 at 14:52

2 Answers2

3

Here is a reduced example (works in a brand new winforms project, with a button called Button1 and label called Label1 manually placed on the form) - valid secret sequence is checked when control key is released.

Public Class Form1

  Dim word As String

  Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
    If e.Control AndAlso e.KeyCode <> Keys.ControlKey Then word &= getChar(e)
  End Sub

  Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
    If e.KeyData = Keys.ControlKey Then
      '<---- this is where you need to check against a valid secret sequence
      Label1.Text = word
      word = String.Empty
    End If
  End Sub

  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    MessageBox.Show(word)
  End Sub

  Private Function getChar(e As KeyEventArgs) As Char
    Dim keyValue As Integer = e.KeyValue
    If Not e.Shift AndAlso keyValue >= CInt(Keys.A) AndAlso
                           keyValue <= CInt(Keys.Z) Then
      Return ChrW(keyValue + 32)
    End If
    Return ChrW(keyValue)
  End Function

End Class

Converted getChar from C# (credit goes to this answer).

Community
  • 1
  • 1
Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
1

You could declare string property outside sub that is handling key press. In that sub, every time you capture ctrl+something, you add that something to string and check if it contains word you want.

srka
  • 792
  • 8
  • 20