Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Java Accessible Object Dialog Problem
#4
Quote:Do you know what is the issue with Java that caused DoDefaultAction and JavaAction("click") to not work?
Don't know, but this helped me to understand partially: https://community.oracle.com/thread/2595410
The Java DoDefaultAction function does not return until the dialog is closed. If somebody/something closes it within several seconds, the macro can continue.

Quote:With regards to the PostMessage, how did you get the "0x390001" and "0xC0390001" parameters?
It is documented in MSDN library. Function SendKeysToWindow2 (below) calculates them. But I simply took them from Spy++, it is a program installed with older versions of Visual Studio and maybe can be downloaded separately, or you can find similar programs. It monitors and decodes Windows messages received by a window. Useful in automation.

To send keys to an inactive window better use this function. It translates QM key codes and posts messages. Also it supports modifier keys (Ctrl etc) which cannot be simply posted like other keys. Not very reliable, with some windows or in some conditions may be too fast, then try to make it wait longer after posting messages.

Function SendKeysToWindow2
Code:
Copy      Help
;/
function hwnd ARRAY(KEYEVENT)'a

;Sends keys to a child window using WM_KEYDOWN/WM_KEYUP messages.
;The window can be inactive, but with some windows then does not work.

;hwnd - child window handle. Or main window handle, if it receives keys.
;a - the <help>key</help> function.

;EXAMPLE
;int hwnd=id(15 "Notepad")
;SendKeysToWindow2 hwnd key("text[]" Cs)


int i lparam m up alt ati
str sk
ifk(A) alt=1

for i 0 a.len
,KEYEVENT k=a[i]
,if(k.flags&0x80) i+1; continue ;;wait
,sel(k.vk)
,,case [16,17,18]
,,int th1=GetCurrentThreadId
,,int th2=GetWindowThreadProcessId(hwnd &i)
,,ati=AttachThreadInput(th1 th2 1)
,,sk.all(256)
,,0.01
,,break

for i 0 a.len
,k=a[i]
,
,if(k.flags&0x80) ;;wait
,,i+1
,,opt waitmsg -1
,,wait (a[i].wt/1000.0)
,,continue
,
,lparam=k.sc<<16|1
,if(k.flags&KEYEVENTF_EXTENDEDKEY) lparam|0x01000000
,if(k.flags&KEYEVENTF_KEYUP) lparam|0xC0000000; up=1; else up=0
,
,if(alt) m=iif(up WM_SYSKEYUP WM_SYSKEYDOWN); lparam|0x20000000
,else m=iif(up WM_KEYUP WM_KEYDOWN)
,
,if(k.vk=VK_RETURN) 0.01 ;;some controls, eg PSPad, would insert new line too early
,
,PostMessage hwnd m k.vk lparam
,0.01
,
,sel(k.vk)
,,case [16,17,18] ;;modifier keys
,,;wait while processes prev keys
,,if(i) SendMessage hwnd 0 0 0
,,0.01
,,
,,GetKeyboardState sk
,,sk[k.vk]=iif(up 0 0x80)
,,SetKeyboardState sk
,
,if(k.vk=VK_MENU) alt=!up

if(ati) ati=AttachThreadInput(th1 th2 0)

Tested with the same Java window and it works.

Macro Macro2854
Code:
Copy      Help
int w=win("Java Control Panel" "SunAwtFrame")
;act w
Acc a.Find(w "push button" "Network Settings..." "" 0x1001)

;a.DoDefaultAction ;;bad
;a.JavaAction("click") ;;bad

int isActive=w=win
if(!isActive) SendMessage w WM_ACTIVATE WA_ACTIVE w ;;let the window think it is active, else it ignores the keys
SendKeysToWindow2 w key(An)
if(!isActive) SendMessage w WM_ACTIVATE WA_INACTIVE 0

0.5
int w1=win("Network Settings" "SunAwtDialog")
Acc a1.Find(w1 "push button" "Cancel" "" 0x1001)
a1.DoDefaultAction


;Also tried to post mouse click messages, but it does not work with Java windows.


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)