Image Image Image




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: iPoker - Access Textbox for Bet sizing
PostPosted: Thu Dec 20, 2012 6:54 am 
Offline
New member
User avatar

Posts: 3
Favourite Bot: Say what?
Hi community,

I have a question about accessing the Textbox for iPoker in C#. My code looks like follows (excerpt). Don't be scared by the amount :)

Code:
// Relative coordinates of the textfield
private int[] X_BET_SIZE_FIELD = { 723, 776 };
private int[] Y_BET_SIZE_FIELD = { 512, 524 };

// Key codes for function SendKeys.SendWait(string keystroke)
private string SENDKEY_ENTER = "{ENTER}";
private string SENDKEY_F3 = "{F3}";

/*
* Function that causes headache. Should in three steps
* (1) Create proper formatted bet-size string
* (2) Double click on the textbox. This causes the content of the textbox to be marked (like pressing STRG + A)
* (3) Send bet-size valued keystrokes. Since the content of the textbox is marked this should overwrite the content of the
*      box
*/
public void regular_custom_size_raise(double bet_size_in_cents) {

    string s_bet_size = (bet_size_in_cents / 100).ToString("0.00");
    string s_send_keys = s_bet_size + SENDKEY_ENTER + SENDKEY_F3;                  // (II)
    // string s_send_keys = s_bet_size;                                            // (III)

    this.left_click_double_on_button(X_BET_SIZE_FIELD, Y_BET_SIZE_FIELD);

    this.send_keystroke(s_send_keys);                                               // (I)
}

/*
* Helper function to simulate keyboard input. Works in two steps:
* (1) Table window becomes active window so it can accept keyboard inputs
* (2) Send keystroke using class SendKeys
*/
private void send_keystroke(string keystroke) {
    UnsafeNativeFunctions.SetForegroundWindow(hwnd_window);
    SendKeys.SendWait(keystroke);
}

/*
* Helper function simulate a double leftclick on a given rectangle. Works in three steps:
* (1) Table window becomes active window every pixel can be reached
* (2) Convert relative window coordinates to absolute screen coordinates. Use some randomness to not always click at the
*      same "relative" pixel (Hope one understands what I mean by that)
* (3) Send events to simulate a double mouseclick using helper function 'click_double_left(...)' 
*/
private void left_click_double_on_button(int[] X_BUTTON_COORDS, int[] Y_BUTTON_COORDS) {

    UnsafeNativeFunctions.RECT window_coords;
    int click_x;
    int click_y;

    UnsafeNativeFunctions.SetForegroundWindow(hwnd_window);

    window_coords = new UnsafeNativeFunctions.RECT();
    UnsafeNativeFunctions.GetWindowRect(this.hwnd_window, ref window_coords);

    click_x = window_coords.left + X_BUTTON_COORDS[0] + rand.Next(X_BUTTON_COORDS[1] - X_BUTTON_COORDS[0]);
    click_y = window_coords.top + Y_BUTTON_COORDS[0] + rand.Next(Y_BUTTON_COORDS[1] - Y_BUTTON_COORDS[0]);

    this.click_double_left(click_x, click_y);
}

/*
* Helper function to simulate a double leftclick. Works in three steps
* (1) Make window active
* (2) Reposition cursor to given coordinates
* (3) Fire events to simulate doubleclick
*/
private void click_double_left(int x_abs, int y_abs) {
    UnsafeNativeFunctions.SetForegroundWindow(hwnd_window);
    Cursor.Position = new System.Drawing.Point(x_abs, y_abs);
    UnsafeNativeFunctions.mouse_event((uint)(UnsafeNativeFunctions.MouseEventFlags.LEFTDOWN), 0, 0, 0, IntPtr.Zero);
    UnsafeNativeFunctions.mouse_event((uint)(UnsafeNativeFunctions.MouseEventFlags.LEFTUP), 0, 0, 0, IntPtr.Zero);
    UnsafeNativeFunctions.mouse_event((uint)(UnsafeNativeFunctions.MouseEventFlags.LEFTDOWN), 0, 0, 0, IntPtr.Zero);
    UnsafeNativeFunctions.mouse_event((uint)(UnsafeNativeFunctions.MouseEventFlags.LEFTUP), 0, 0, 0, IntPtr.Zero);
}


When I now call 'regular_custom_size_raise(x)' the bet-size is posted in the chat; the performed action is a minraise.

After removing line (I) I see the double-clicking part working proper. The cursor is positioned above the textbox and the content is selected (and can be overwritten by simply pressing a numeric-key).

So I decided to replace line (II) by line (III) and insert (I) again. What happens is:
- a double click is performed on the Textbox (so the content is highlighted/ marked)
- the proper formatted bet-size x.toString("0.00") is posted in the chat

Does anyone have an explanation for that? Or does anyone have an idea how to deal with this - or how to access the textbox directly by handle?

Open for everything. Thanks ahead for suggestions

Best,
Ben


Top
 Profile E-mail  
 
 Post subject: Re: iPoker - Access Textbox for Bet sizing
PostPosted: Thu Dec 20, 2012 9:26 am 
Offline
New member
User avatar

Posts: 3
Favourite Bot: Say what?
Solved it. The issue was a simple race condition.

Code:
System.Threading.Thread.Sleep(150);


Between the double click and SendKeys deals with the problem. Thx anyway :)


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 


Who is online

Users browsing this forum: Google and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: