HotKeys with Options

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 1110 Views - Last Post: 12 August 2013 - 08:53 AM Rate Topic: -----

#1 Neph1x  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 110
  • Joined: 19-November 11

HotKeys with Options

Posted 01 July 2013 - 05:40 AM

Hi, i need a help with Hotkeys but with options!

let's say you have two forms and first form is for options, and there is a combobox with few options for hotkey button (PrintScrn, F12 and S)

and another form is "main" form and let's say i need hotkey for e.g. active my software, now my question is how can i create hotkey to support this options.

my hotkey code

If GetKeyPress(Keys. HOW TO DETECT WHICH OPTION YOU CHOOSE ON COMBOBOX ) Then

        Else

        End If


Thank you very much.

This post has been edited by Neph1x: 01 July 2013 - 05:41 AM


Is This A Good Question/Topic? 0
  • +

Replies To: HotKeys with Options

#2 dday9  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 86
  • Joined: 17-April 13

Re: HotKeys with Options

Posted 01 July 2013 - 08:02 AM

This is where My.Settings comes into play. Assuming you're using VS 2010:

  • Double Click 'My Project' in the solutions explorer
  • Click on the 'Settings' tab
  • Type in the name of the setting
  • Chose the type as System.Windows.Form.Keys
  • Set the Scope to 'User'


If keys is not available in the Type then:
  • Choose Browser
  • Click on System.Windows.Forms
  • Click on {}System.Windows.Forms
  • Chose Keys
  • Click OK


Then use the combobox to get/set the hotkey setting.
Was This Post Helpful? 1
  • +
  • -

#3 Neph1x  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 110
  • Joined: 19-November 11

Re: HotKeys with Options

Posted 01 July 2013 - 09:16 AM

Thank you, please can you give me some example how can i get/set combobox value to setting?
This is the first time that i working with that...Thank you!
Was This Post Helpful? 0
  • +
  • -

#4 dday9  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 86
  • Joined: 17-April 13

Re: HotKeys with Options

Posted 01 July 2013 - 10:57 AM

Working with My.Settings is very simple. Here is an MSDN article that goes into a bit of explanation. But here is a quick example using your situation:
'A Must!
Option Strict On
Option Explicit On
Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'Get the settings
        Label1.Text = String.Format("Hotkey1: {0}{1}Hotkey2:{2}", My.Settings.hotkey_combo1.ToString, Environment.NewLine, My.Settings.hotkey_combo2.ToString)

        'Set up the combobox's properites
        With ComboBox1
            .Location = New Point(0, 0)
            .DropDownStyle = ComboBoxStyle.DropDownList
            'Add asdw control, alt, and shift
            .Items.AddRange({Keys.A, Keys.S, Keys.D, Keys.W, Keys.Control, Keys.Alt, Keys.Shift})
        End With

        'Set up the combobox's properites
        With ComboBox2
            .Location = New Point(0, 40)
            .DropDownStyle = ComboBoxStyle.DropDownList
            'Add asdw control, alt, and shift
            .Items.AddRange({Keys.A, Keys.S, Keys.D, Keys.W, Keys.Control, Keys.Alt, Keys.Shift})
        End With
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        'Set the settings
        My.Settings.hotkey_combo1 = DirectCast(ComboBox1.SelectedItem, Keys)
        My.Settings.hotkey_combo2 = DirectCast(ComboBox2.SelectedItem, Keys)

    End Sub
End Class


Was This Post Helpful? 1
  • +
  • -

#5 Neph1x  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 110
  • Joined: 19-November 11

Re: HotKeys with Options

Posted 01 July 2013 - 05:48 PM

Thank you very much! You really helped me :rockon:
Was This Post Helpful? 0
  • +
  • -

#6 Neph1x  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 110
  • Joined: 19-November 11

Re: HotKeys with Options

Posted 09 August 2013 - 09:29 AM

One more problem :(
How can i add ({Keys.Control + keys.t, Keys.Shift})
When i press control + t to do something, not only control.
When i do this "Keys.Control + keys.t" everything is ok, but vb add value of control and value of t :(
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8891
  • View blog
  • Posts: 33,338
  • Joined: 12-June 08

Re: HotKeys with Options

Posted 09 August 2013 - 09:36 AM

Put a breakpoint in your event... *LOOK* at what the 'e' event arg is in the watch window. You'll notice there are control, shift, and alt boolean properties at the same level as the key data... hmmm.. I wonder what they tell ya?
Was This Post Helpful? 0
  • +
  • -

#8 Neph1x  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 110
  • Joined: 19-November 11

Re: HotKeys with Options

Posted 09 August 2013 - 09:44 AM

http://prntscr.com/1kakpp

I was trying everything, when i set + vb add this 2 value, when i set * vb multiply this 2 value and also i was try with 'add', 'or' but nothing...i don't have anymore ideas :(

This post has been edited by Neph1x: 09 August 2013 - 09:46 AM

Was This Post Helpful? 0
  • +
  • -

#9 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8891
  • View blog
  • Posts: 33,338
  • Joined: 12-June 08

Re: HotKeys with Options

Posted 09 August 2013 - 09:45 AM

I am unsure what to take away from that image response.
Was This Post Helpful? 0
  • +
  • -

#10 Neph1x  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 110
  • Joined: 19-November 11

Re: HotKeys with Options

Posted 09 August 2013 - 09:50 AM

:nottalkingtoyou: Really i don't know what to say..
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8891
  • View blog
  • Posts: 33,338
  • Joined: 12-June 08

Re: HotKeys with Options

Posted 09 August 2013 - 09:52 AM

Quote

I was trying everything, when i set + vb add this 2 value, when i set * vb multiply this 2 value and also i was try with 'add', 'or' but nothing...i don't have anymore ideas :(

Okay.. editing the post after the fact is a bit odd.. but my question is now - what?


After skimming the above - I am unclear why you are not using the control's "key down" event either.
Was This Post Helpful? 0
  • +
  • -

#12 Neph1x  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 110
  • Joined: 19-November 11

Re: HotKeys with Options

Posted 09 August 2013 - 09:56 AM

Because i wanna save this hotkey setting after, and i know how to do that on this way, everything works fine except that, when i have only one button everything is ok, but when i have combination of 2 buttons (controlkey + t) that works to but vb doesn't recognize that as hotkey or let's say button.
Was This Post Helpful? 0
  • +
  • -

#13 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8891
  • View blog
  • Posts: 33,338
  • Joined: 12-June 08

Re: HotKeys with Options

Posted 09 August 2013 - 09:59 AM

Ah.. I see.. so you want folks to assign their own keyboard commands for your app?

Gotcha.. well then store two values in your my.settings. The "<key>,<modifier>". When your app runs it splits apart on the comma and knows to check for one key or two.
Was This Post Helpful? 0
  • +
  • -

#14 Neph1x  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 110
  • Joined: 19-November 11

Re: HotKeys with Options

Posted 09 August 2013 - 10:05 AM

Yes, you are right,

i'm not sure that i understand you complete what are you mean.

This is my 'check code' for pressed key in timer1.

Private Declare Function GetKeyPress Lib "user32" Alias "GetAsyncKeyState" (ByVal key As Integer) As Boolean
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        If GetKeyPress(My.Settings.hotkey_combo1) Then

            MsgBox("Options 1")


        Else

        End If

        If GetKeyPress(My.Settings.hotkey_combo2) Then

            MsgBox("Options 2")


        Else

        End If
    End Sub

Was This Post Helpful? 0
  • +
  • -

#15 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8891
  • View blog
  • Posts: 33,338
  • Joined: 12-June 08

Re: HotKeys with Options

Posted 09 August 2013 - 10:07 AM

Ah.. what? Why are you using
" Private Declare Function GetKeyPress Lib "user32" Alias "GetAsyncKeyState" (ByVal key As Integer) As Boolean " ?

Why are you using a timer tick event?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2