Locked windows api

  • Saturday, December 22, 2007 10:28 PM
     
     

     

    I need to know how I can crate a windows application that will interact with another gaming application on my computer by being able to click buttons according to incoming information from the game.  What is windows api?  If this won't do it what program related to express will let me retrieve data from a game and then allow me to interact with that game?

All Replies

  • Sunday, December 23, 2007 6:02 PM
     
     
    How can I have my program click on other programs on my computer that are running?

     

  • Wednesday, December 26, 2007 4:19 AM
     
     Answered

     karlkruse wrote:
    How can I have my program click on other programs on my computer that are running?

     

    To simulate mouse click on where you expect, you can P/Invoke the WindowFromPoint and SendMessage APIs to send BM_CLICK message.

    Code Block

    Imports System.Runtime.InteropServices

    Public Class Form1

     

        <DllImport("user32.dll")> _

    Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByRef lParam As IntPtr) As IntPtr

        End Function

        <DllImport("user32.dll")> _

    Shared Function WindowFromPoint(ByVal pnt As Point) As IntPtr

        End Function

     

        Const BM_CLICK As Integer = &HF5&

     

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

            Timer1.Enabled = True

            Timer1.Interval = 1000

        End Sub

     

        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

            'Dim pnt As Point = Me.PointToScreen(Button1.Location)

            Dim pnt As Point = New Point(10, 10) ' Specify the location where you want to click.

            Dim hWnd As IntPtr = WindowFromPoint(pnt)

            If hWnd <> IntPtr.Zero Then

                SendMessage(hWnd, BM_CLICK, 0, IntPtr.Zero)

                'SendMessage(Me.Button1.Handle, BM_CLICK, 0, IntPtr.Zero)

            End If

     

        End Sub

     

    End Class

    Similar issues:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2246644&SiteID=1

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2594034&SiteID=1

     

    Happy New Year!

    Martin

  • Wednesday, December 26, 2007 4:24 AM
     
     

    Thanks, I am still trying to understand.  Is there also a way I can like read a card image on a piece of software and turn that into a value of some sort to tell different cards apart from each other in software and then be able to have those values stored and then retrieved when they show up in the software?

  • Wednesday, December 26, 2007 4:31 AM
     
     

     "Dim pnt As Point = New Point(10, 10) ' Specify the location where you want to click."

     

    -> Further, to determine the point coordinate of those Buttons on your game window, you can run the following programe to get current point coordinate where you point Cursor to.

    Prerequisites: Create a form named Form2 and copy all code to Form2.vb.

    Code Block

    Imports System.Runtime.InteropServices

    Public Class Form2

        Private Structure MSLLHOOKSTRUCT

            Public pt As Point

            Public mouseData As Int32

            Public flags As Int32

            Public time As Int32

            Public extra As IntPtr

        End Structure

     

        Private _mouseHook As IntPtr

        Private Const WH_MOUSE_LL As Int32 = 14

        Private Delegate Function CallBack(ByVal nCode As Int32, ByVal wParam As IntPtr, ByRef lParam As MSLLHOOKSTRUCT) As Int32

        <MarshalAs(UnmanagedType.FunctionPtr)> Private _mouseProc As CallBack

        Private Declare Function SetWindowsHookExW Lib "user32.dll" (ByVal idHook As Int32, ByVal HookProc As CallBack, ByVal hInstance As IntPtr, ByVal wParam As Int32) As IntPtr

        Private Declare Function UnhookWindowsHookEx Lib "user32.dll" (ByVal hook As IntPtr) As Boolean

        Private Declare Function CallNextHookEx Lib "user32.dll" (ByVal idHook As Int32, ByVal nCode As Int32, ByVal wParam As IntPtr, ByRef lParam As MSLLHOOKSTRUCT) As Int32

        Private Declare Function GetCurrentThreadId Lib "kernel32.dll" () As Integer

        Private Declare Function GetModuleHandleW Lib "kernel32.dll" (ByVal fakezero As IntPtr) As IntPtr

     

        Public Function InstallHook() As Boolean

            If _mouseHook = IntPtr.Zero Then

                _mouseProc = New CallBack(AddressOf MouseHookProc)

                _mouseHook = SetWindowsHookExW(WH_MOUSE_LL, _mouseProc, GetModuleHandleW(IntPtr.Zero), 0)

            End If

            Return _mouseHook <> IntPtr.Zero

        End Function

     

        Public Sub RemoveHook()

            If _mouseHook = IntPtr.Zero Then Return

            UnhookWindowsHookEx(_mouseHook)

            _mouseHook = IntPtr.Zero

        End Sub

     

        Private Shared Function MouseHookProc(ByVal nCode As Int32, ByVal wParam As IntPtr, ByRef lParam As MSLLHOOKSTRUCT) As Int32

            Debug.Print("Message = {0}, x={1}, y={2}", wParam.ToInt32, lParam.pt.X, lParam.pt.Y)

           ' Get the current cursor coordinate

            Form2.Text = "Current Point: " & lParam.pt.X & " " & lParam.pt.Y         ' 

            Return CallNextHookEx(WH_MOUSE_LL, nCode, wParam, lParam)

        End Function

     

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

            InstallHook()

        End Sub

     

        Private Sub Form2_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed

            RemoveHook()

        End Sub

    End Class

    Trackback: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=698653&SiteID=1

     

  • Wednesday, December 26, 2007 4:35 AM
     
     

    I need to know what cards are displayed on a outside screen.  How could I get visual basic to be able to read a layout of 5 cards and tell me code witch cards those are.  I would need this to repeat for all possible 5 card combinations for all 53 cards.

  • Wednesday, December 26, 2007 4:41 AM
     
     

     

    A problem for you is that you do not understand the complexity of what you are asking. I'm serious about that.

     

    If I responded, you can achieve this by doing a fourier transform on the bits in the card images... is the next question going to be, "whats a fourier transform?"

  • Wednesday, December 26, 2007 4:48 AM
     
     
    well i don't know what that is where could i find out about it?  I  need the absolute quickets way to read varying 5 card layouts on a external software like a video poker game.  Would i have to set these images equal to variables or.... I am not sure about the whole process?

     

  • Wednesday, December 26, 2007 5:30 AM
     
     

     

    Whatever you do, it will not be quick at all. It's a problem that requires a lot of skill.

     

    to find out about fourier Google fourier analysis.

  • Wednesday, December 26, 2007 5:45 AM
     
     Answered

    "Would i have to set these images equal to variables or.... I am not sure about the whole process? "

     

    You get the bit data and do a fourier analysis and get a fourier signature that when compared to signatures you have stored will allow you to identify a card.

  • Wednesday, December 26, 2007 2:12 PM
     
     

    What do you mean it won't be quick at all?  It only puts up 5 cards out of 53 each time.  So for the project to recognize 5 cards out of 5 previously stored signatures that would take how long?  There must be a quick way that if i can create a form small enough so that both the video poker software and the form can stay active on one screen is there a quicker way by utilizing this setup?  Kind of like a poker program reading cards from a poker game but for vp.

  • Wednesday, December 26, 2007 2:18 PM
     
     

     

    I am saying implimenting this will not not be quick.
  • Wednesday, December 26, 2007 2:20 PM
     
     
    ok but it will run quick right?

     

  • Wednesday, December 26, 2007 4:29 PM
     
     

     

    That will depend on your skill as an implementer. What you are talking about would be challenging for a skilled developer.

     

    Your first problem is to find a fourier software on the net.

  • Wednesday, December 26, 2007 4:39 PM
     
     
    So visual basic does not have the capability to actually obtain information from game states from external programs.

     

  • Wednesday, December 26, 2007 5:13 PM
     
     

     

    VB is a professional programming language. It is not about games unless you write it. You can write something like you want BUT it is non-trivial.

     

    People who aren't familiar with software ask for these these but a really good metric on what is good practice and what isn't is to ask yourself, "Hmmmm, have I ever seen microsoft software do that?"

  • Wednesday, December 26, 2007 5:21 PM
     
     
    Well i think microsoft software can.  I think all you need is some dll involved.  If i gave you a link of a really simple free program that you can't download from a site that is able to read cards from a software just like the one i am trying to use.  It is a blackjack advisor program and it is able to read card values and then give you the proper strategy.  This is all i want to do but with video poker.  the program is really small and i think you looked at it you can find out what type of process it goes through to read the card values.  I want my progam to have the same speed as this one.  Go to bonusbots.com and don't download any of the other programs unless you want but there is an evaluation version of the blackjack advisor that will work together with a casino software and will use the card values to return a proper strategy.  I basically am creating the same exact program but that will tell you proper advice for another game ( video poker).

     

  • Wednesday, December 26, 2007 5:59 PM
     
     

     

    Are these games coming from the Web and played on a webbrowser?

     

    "Well i think microsoft software can.  I think all you need is some dll involved."

     

    Fine, if it's so easy all you have to do is find "some dll".

  • Wednesday, December 26, 2007 6:58 PM
     
     
    i don't know how.  The games I want to play will be on a downloaded software that won't be on the internet.  I want the download version of the casino.  If you would like to download bet royal casino then just download the first blackjack bot you should be able to get it to play up to 100 free hands.  I just go it to work with bet royal after creating a account.  Is there any way i can run some type of program that will watch this program in action while it retrieves card information and pushed buttons to see what process it is going through to do this.  I have the program working on my computer i just need  way to find out how it is doing the clicking and reading cards from the software. 

     

  • Wednesday, December 26, 2007 7:24 PM
     
     

     

    I am not religious but I don't believe in gambling and if you've noticed I rarely do much for gamers on this board. Why? Iguess it because I am a relative pioneer in this field and I absolutely cannot take gaming seriously.

     

    I wish you luck on your project. At this point, I am leaving the thread.

  • Wednesday, December 26, 2007 8:50 PM
     
     

    I don't even use it for real money.

    i just use it to get statistics through playing play money.

     

  • Wednesday, December 26, 2007 9:27 PM
     
     

     

    1.) We are not communicating. I do not believe you have really heard what I've written. I don't know how you bots have done this; I know how I would do it.

     

    2.) I believe how I would do it exceeds your current skill level. Therefore my ability to serve you is close to nil.

     

    3.) If you want to see what I mean, undertake a small fourier library.

     

    4.) when you've done that. Come back.

  • Thursday, December 27, 2007 1:12 AM
     
     Answered

     

    Allright,

     

    I found a .Net FFT Library written in .Net 2001 C#.

     

    http://sourceforge.net/project/showfiles.php?group_id=91280

     

    I have not looked at it but from what I can see, it has a good reputation and will eventually do what you want.

     

    You could start by downloading C# express and converting it to recent c#. I'm interested in this. You're proposed project is not a simple one. I am interested in this library.

     

     

  • Thursday, December 27, 2007 2:55 AM
     
     

    i  looked at it and i think there is a simpler way if you download the program you will see it is much quick than a fourier type process meaning it only has to check a coupole of pixels on a card.  The program is just a little form window that is able to do it.  So it isn't out of my reach becasue i am just trying to recreate something.

  • Thursday, December 27, 2007 3:24 AM
     
     

     

    There's a problem. I'm not going to learn anything from examining a couple of pixels. And I know you won't identify cards based on a couple of pixels unless they are designed they way.
  • Thursday, December 27, 2007 3:27 AM
     
     
    well i am just saying you should watch the program work to get an idea of how you thin it is pushing buttons and obtaining card info. 

     

  • Thursday, December 27, 2007 3:29 AM
     
     

     

    You aren't listening to me again.

     

    I am not interested in games or cards at all. What I am interested in is discriminating between images using fourier analysis. That coincides with your interests. My only motivation for looking at this is Fourier, otherwise, i wish you well.

  • Thursday, December 27, 2007 3:30 AM
     
     
    I am just saying that you should look at the program run while it pushes buttons and reads cards to see how it is doing it.

     

  • Thursday, December 27, 2007 3:31 AM
     
     

    ok if i get it to work do you want the news?

     

     

  • Thursday, December 27, 2007 3:32 AM
     
     

     

    Unless the cards are designed for it, it won't work. You cannot do what you are proposing.
  • Thursday, December 27, 2007 3:34 AM
     
     
    dude if you watch the program run you will see i have to recreate it the procedures and that is all.

     

  • Thursday, December 27, 2007 3:36 AM
     
     

     

    I'm a woman. You're a dude. I don't care about cards or games at all. When are you going to get that?