dcsimg
Results 1 to 9 of 9

Thread: Need help for macros to work on 64 Bit

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2014
    Posts
    4

    Exclamation Need help for macros to work on 64 Bit

    I can't seem to make hotkeys to work on 64 bits im using visual studio 2013 btw. I have read about the LongPtr function which for some strange reason doesnt work with my vb so here's how im declaring As Long.. Should be correct idk what happens, i used to do it like this but now it just doesnt work. Can someone help me

    Code:
    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 mouseclickup = 4
        Private Const mouseclickdown = 2
        Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer

  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need help for macros to work on 64 Bit

    Thread moved from VB6 to VB.NET forum

    It appears that you are using the VB6 form of the API. You need to use the VB.NET version


    Welcome to the Forums btw
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: Need help for macros to work on 64 Bit

    Ermm, the function is GetAsyncKeyState(ByVal vKey As System.Windows.Forms.Keys) so what's LongPtr got to do with it?

    In any event you would be far better of using the hotkey functions. Use the search window on this page for hot keys ... it's been discussed several times in the last few months.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2014
    Posts
    4

    Re: Need help for macros to work on 64 Bit

    Quote Originally Posted by dunfiddlin View Post
    Ermm, the function is GetAsyncKeyState(ByVal vKey As System.Windows.Forms.Keys) so what's LongPtr got to do with it?

    In any event you would be far better of using the hotkey functions. Use the search window on this page for hot keys ... it's been discussed several times in the last few months.
    It's kind of weird for me because if im not wrong it should work on 64 bits since its Declared as Long, now people says that i need to use LongPtr instead of long for it to work on 64 bits, the code is correct i just press the Key and it does nothing. Thanks for your response

  5. #5
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Need help for macros to work on 64 Bit

    hector,

    You say macro.

    Are you running your code in an MS office product 2010 or later installed as a 64 bit app?

    If so you will be dealing with VBA 7 64 bit which has its own 64 bit variable types.
    LongLong
    LongPtr
    Etc...

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2014
    Posts
    4

    Re: Need help for macros to work on 64 Bit

    Quote Originally Posted by Gruff View Post
    hector,

    You say macro.

    Are you running your code in an MS office product 2010 or later installed as a 64 bit app?

    If so you will be dealing with VBA 7 64 bit which has its own 64 bit variable types.
    LongLong
    LongPtr
    Etc...
    Well im using Visual studio 2013 (Visual Basic) i just dont know why when i press a hotkey like f1 it doesnt work on 64 bits. I think my code is correct idk why this happens. could u help me?

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: Need help for macros to work on 64 Bit

    It's kind of weird for me because if im not wrong it should work on 64 bits since its Declared as Long
    Just because you have a 64 bit machine doesn't mean every variable has to be 64 bits. How would that even work with strings, for example? Use the type that the function requires. That won't change whatever your machine specification.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  8. #8

    Thread Starter
    New Member
    Join Date
    Jan 2014
    Posts
    4

    Re: Need help for macros to work on 64 Bit

    Quote Originally Posted by dunfiddlin View Post
    Just because you have a 64 bit machine doesn't mean every variable has to be 64 bits. How would that even work with strings, for example? Use the type that the function requires. That won't change whatever your machine specification.
    I tried doing it like the 32 bits way its not working check this:
    Code:
    Public Class Form1
        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 mouseclickup = 4
        Private Const mouseclickdown = 2
        Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Timer1.Start()
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Timer1.Stop()
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            Windows.Forms.Cursor.Position = New Point(TextBox1.Text, TextBox2.Text)
            mouse_event(mouseclickdown, 0, 0, 0, 0)
            mouse_event(mouseclickup, 0, 0, 0, 0)
        End Sub
    
        Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
            Dim hotkey As Boolean
            hotkey = GetAsyncKeyState(Keys.F1)
            If hotkey = True Then Timer1.Start()
            Dim hotkey1 As Boolean
            hotkey1 = GetAsyncKeyState(Keys.F2)
            If hotkey1 = True Then Timer1.Stop()
        End Sub
    
        Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
            Dim Posicion As Boolean
            Posicion = GetAsyncKeyState(Keys.F5)
            If Posicion = True Then
                TextBox1.Text = MousePosition.X : TextBox2.Text = MousePosition.Y
            End If
            If Posicion = False Then
            End If
    
        End Sub

  9. #9
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: Need help for macros to work on 64 Bit

    You have 3 timers (quite why I know not) and you only start one of them (unless you have them set Enabled at Design Time?) So, no, it doesn't work!

    The declaration for GetAsyncKeyState, I already gave you. The one for mouse_event has all parameters as Int32 (which is the same as Integer these days).
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width