❓ [Help]64Bit Hotkeys[Solved]

Posts 16–28 of 28 · Page 2 of 2
Still getting an error. This is my current opening code

Code:
 Imports System.Runtime.InteropServices

Public Class Form1

    Public Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer

    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer

    Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy _
    As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

    Private Const MOUSELEFTDOWN = &H2 '  left button down 
    Private Const MOUSELEFTUP = &H4 '  left button up
Getting the following error:
Code:
Error	1	'Declare Ansi Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (vKey As Long) As Integer' has multiple definitions with identical signatures.
Try this

[php]
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As IntPtr) As IntPtr
[/php]


Oh............. U have two occurrences, remove one.........
wait one sec i had an obvious mistake, declared GetAsyncKeySet twice.
Nvm, you seen it
Still isn't working...Is my hotkeys timer supposed to be enabled :O
Are you getting any errors?

If not, then yes, enable the timer.

I don't know your whole code, i am assuming your timer is checking for hotkeys.
wait I shall tidy up my code and post the whole thing here, it's not very long. Might speed this up a bit.
[Help] Hotkeys with 64-bit Vista.
Yes I am aware that there is a topic on this very page entitled the very same thing. I also posted there but no-one checks 'cos it's already been [solved]

Anyway basically my problem is this. My hotkeys do nothing at the moment. I'm returning no errors from Visual Basic Debugger either, plain and simple nothing happens when i press the assigned hotkeys "F5" and "F6". This is an AC i've been making to learn some VB. I know the actual AC works because it works fine when i just change to a command button instead of using hotkeys.

Here's what the form looks like:



And the code:

Code:
 
Public Class Form1

    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer


    Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy _
    As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

    Private Const MOUSELEFTDOWN = &H2 

    Private Const MOUSELEFTUP = &H4

    Private Sub Clicks_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clicks.Tick

        Clicks.Interval = TextBox1.Text

        mouse_event(MOUSELEFTDOWN, 0, 0, 0, 0)

        mouse_event(MOUSELEFTUP, 0, 0, 0, 0)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        TextBox1.Text = HScrollBar1.Value

    End Sub

    Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll

        TextBox1.Text = HScrollBar1.Value

    End Sub

    Private Sub Hotkeys_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Hotkeys.Tick

        Dim Hotkey1 As Boolean
        Hotkey1 = GetAsyncKeyState(Keys.F5)
        If Hotkey1 = True Then
            Clicks.Enabled = True

        End If

        Dim Hotkey2 As Boolean
        Hotkey2 = GetAsyncKeyState(Keys.F6)
        If Hotkey2 = True Then
            Clicks.Enabled = False

        End If


    End Sub
End Class
My clicks timer is set to disabled and interval 1000 upon loading the form.
My hotkeys timer is enabled and interval set to 100

I'm running Vista 64-bit OS and I know that there is a problem with this line not being compatible with 64-bit systems:

Code:
 Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
But I don't know how to fix this. So, any help would be greatly apppreciated.
Threads merged, it was marked solved because it was solved for the original OP
yes, I double posted, i did it for the sake of the user to realize his question was answered.

This was performed and worked on a Windows 7 64 bit OS

I added a timer and called it hotkeys

I then added to the namespace

[php]
Imports System.Runtime.InteropServices
[/php]

Then I declared GetAsyncKeyState as a function

[php]
<DllImport("user32.dll")> _
Private Shared Function GetAsyncKeyState(ByVal vKey As Integer) As UShort
End Function
[/php]

On form load I turned the timer on
[php]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

hotkeys.Enabled = True

End Sub
[/php]

In the hotkeys timer I add this code

[php]
Private Sub hotkeys_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hotkeys.Tick
Dim Hotkey1 As Boolean
Hotkey1 = GetAsyncKeyState(Keys.F5)
If Hotkey1 = True Then
MsgBox("f5")
End If



End Sub
[/php]

I hit F5 and got a messagebox.


Overall my code looked like this

[php]
Imports System.Runtime.InteropServices
Imports System.Environment

Public Class Form1
<DllImport("user32.dll")> _
Private Shared Function GetAsyncKeyState(ByVal vKey As Integer) As UShort
End Function



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

hotkeys.Enabled = True

End Sub



Private Sub hotkeys_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hotkeys.Tick
Dim Hotkey1 As Boolean
Hotkey1 = GetAsyncKeyState(Keys.F5)
If Hotkey1 = True Then
MsgBox("f5")
End If



End Sub
End Class
[/php]

as a test, see if that works for you, and let us know, and continue in this thread, no need to duplicate threads...
NextGen1, have my children plawks. Thank you so much! that fixed it all. Sorry about the double thread :S. WOOOOOOOOOOOT
Its not marked solved >.<
Marked Solved, avoid posting unless necessary and <=7 days
Posts 16–28 of 28 · Page 2 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us