Releasing a key under a specific time reset the sequence? - sequence

So i got this code its working fine. Its for a sword fighting game.
If i hold down the left mouse button (LMB) it will send the key 5 (slash attack) and if i release the LMB it send the key 7 (feint). Same goes for the key 6 (overhead attack) and if i release the LMB it send the key 7 (feint).
So the sequence is like this 5,6,5,6 etc. working like a charm.
If i dont press the LMB for 1,5 sec the sequence reset itself. So its always be like 5,5,5,5 etc. Its working fine too.
Here is the working code for this:
*lbutton::
send % Seqkeys("5","6")
KeyWait, lbutton
Send, 7
return
Seqkeys(params*){
static s:=0, c:=0, t:=1500
max := params.MaxIndex()
(A_TickCount-s<=t && (c+=1)<=max) ? c : c:=1, s:=A_TickCount
return params[c]
}
Now what i want to achieve is that if i release the LMB under 0.3 sec it should always reset the
sequence and send 5,5,5,5 etc.
If the release was over 0.3 sec the sequence should work as default 5,6,5,6 etc.
Sry for the bad english hope u can understand. thx :)

I think I have what you need:
global s:=0, c:=0, t:=1500, t2:=1000/3
*lbutton::
send % Seqkeys("5","6")
KeyWait, lbutton
If (A_TickCount-s < t2)
c := 0
Send, 7
return
Seqkeys(params*) {
global s, c, t
max := params.MaxIndex()
(A_TickCount-s<=t && (c+=1)<=max) ? c : c:=1
s := A_TickCount
return params[c]
}
Example:
Button down: 5
Button up (down for 0.5s): 7
Button down: 6
Button up (down for 0.5s): 7
Button down: 5
Button up (down for 0.2s): 7
Button down: 5
Button up (down for 0.2s): 7
Button down: 5
Button up (down for 0.5s): 7
Button down: 6
Button up (down for 0.5s): 7

Related

AutoHotKey not detecting the right key

So I've made a script to snipe rare cars from Auction House in FH5. Simple script, which should work like I've written it.
Thats my script at the point, it's not doing what it should
Send {Enter}
Sleep, 500
Send {Enter}
PixelGetColor, PixelCol0, 730, 270
if (PixelCol0 = "0xF7F7F7") ;car found
{
Loop
{
PixelGetColor, PixelCol1, 900, 240
if (PixelCol1 != "0xF7F7F7") ;site has loaded/able to press Y
{
Sleep, 500
Send {Y}
}
PixelGetColor, PixelCol2, 671, 444
if (PixelCol2 = "0x351734") ;Check if Y was pressed "correctly"
{
Sleep, 500
FOUNDCAR = 1
break
}
}
regarding the X and Y points of the pixels and the colors, it should work. I have another script to get mouse position and pixel color, so it's 100% correct.
My problem now is, it presses ENTER for 2 times, which works but when it has to press Y to open Auctiondetails, it's not opening the Auctiondetails but the Auction itselfs, like you press Enter again. If you're into FH5, you know what I mean!!!
Would be great if someone knows how to fix that, I'm trying to fix that BS since 2 days now and I'm so close to rage!!!!
Thank you!
I would start with making sure that PixelGetColor works correctly. Without any CoordMode settings the coordinates are relative to the window, and it might be that your mousecoordinates were relative to the screen, thus looking at the wrong pixel. I would replace the code with simple messages that show you the outcome of the PixelGetColor. Use two FH5 windows, one with the right colors and one without, just to check the PixelGetColor behaviour first.

In Adobe Acrobat Javascript, how can I force a page to become "editable" before a certain part of a script acts upon it?

What I'm trying to do: Iterate over each page in a PDF, and extract the number of words on each page.
What is happening instead: The code below will return 0 words for any page that has not become "editable". Although I have selected for all pages to become editable at once, Adobe will not maintain the editability of a page for very long after I have left that page. Side note: It also seems to cap how many pages I can have "editable" at once. This is a problem because right now I'm working with a 10 page selection of a pdf file. This same code will have to work with a 120+ page pdf. Please click 'Edit PDF'-->'Scanned Documents'-->'Settings' to see what I mean by "editable". I have already selected the option to have all pages become editable at once.
What I've tried so far: I've tried various ways to get Acrobat to make the page being iterated upon the "active one" so that it would become editable. I've tried manually setting the page number after each iteration of the for loop, and including an artificial delay like with the h variabled for loop in the sample code. I've tried looking for some sort of method that determines which page is the "active one" but I've had no luck so far.
CurrDoc = app.activeDocs[0]
CurrDoc.title;
NumPagesInDoc = CurrDoc.numPages;
console.println("Document has "+NumPagesInDoc+" pages");
for (j=0; j<NumPagesInDoc; j++)
{
NumWordsOnPage = CurrDoc.getPageNumWords(j);
CurrDoc.pageNum = j;
for(h=0; h<10000;h++); //<--I've tried adding in delays to give time so that
//Acrobat can catch up, but this hasn't worked.
console.println("Page number: "+j+" has this number of words: "+ NumWordsOnPage);
};
Output:
Document has 10 pages
Page number: 0 has this number of words: 309
Page number: 1 has this number of words: 0
Page number: 2 has this number of words: 0
Page number: 3 has this number of words: 0
Page number: 4 has this number of words: 0
Page number: 5 has this number of words: 0
Page number: 6 has this number of words: 0
Page number: 7 has this number of words: 0
Page number: 8 has this number of words: 0
Page number: 9 has this number of words: 158
true
Note: Different pages might work on the output at different times depending on which pages I've clicked on most recently before running the script.
Any guidance or help would be greatly appreciated. Thank you for your time.
So. I'm still not entirely sure what the issue is, but I've found a way to get acrobat to function most of the time.
Before clicking the "make all pages editable" option, zoom all the way out until you can see all the pages in the document. For whatever reason, when I did this, it would seem to refresh something about the settings and once again make all the pages editable. This even seemed to work when I opened a totally different pdf and pressed "make all pages editable" even without zooming out.

How do I display the output of a function of multiple qualtrics sliders in real time?

My colleague and I am designing a survey using Qualtrics. On one page respondents must move a series of sliders.
We need to display the output of a function of the values of the sliders on the same page, ideally also in the form of another slider.
All of this must be done while the respondent moves the sliders.
Concretely, suppose the following:
value of slider 1 = 30;
value of slider 2 = 10;
value of slider 3 = 0
Output to be displayed = 30 x 20 + 10 x 5 + 0 x 15 = 650
where the 20, 5 and 15 are just arbitrary constants in the background.
If the user were to move slider 1 to 31, the displayed output should automatically update in real time to 670.
Any tip on how this is done? We're newbies to qualtrics and completely inexperienced with Java, so we'd be very grateful to anyone willing to provide us with working code. Thanks!
An update on my question, and a clarification after a comment received.
We were of course not asking for someone else to do our job. Just for a pointer in the right direction.
Based on an answer to a different question, I've managed to put this javascript together. It works, which is encouraging..
Code follows.
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var that=this.questionId;
jQuery("<p style='width:100%'><br><strong> Output <span id='OUT'>0</span></strong>").insertAfter("table.sliderGrid");
jQuery(document).on('change', function(){
var firstslider=parseInt(jQuery("[id='"+that+"~1~result']").val());
var secondslider=parseInt(jQuery("[id='"+that+"~2~result']").val());
var N=firstlider+secondslider*2;
jQuery("#OUT").text(N);
});

Appium not working with numeric keyboard

I am trying to enter numbers in an edit field, though the field is focused Appium wasn't able to input the characters. I have tried it in multiple ways, all did not work.
Example 1:
driver.FindElementByXPath("field_to_fill").SendKeys("value");
Example 2:
_driver.PressKeyCode(AndroidKeyCode.KeycodeButton_8);
The field is EditText field, the Android platformVersion: 7.0, and I'm using C#.
This is older, but maybe this will help someone in the future. I ran into this issue yesterday after the app under test changed from a qwerty keyboard to a number pad. (In Java) I was originally using driver.sendKeys(stringOfDigits), which broke with the number pad keyboard showing. Neither driver.setValue(stringOfDigits) nor driver.pressKey(new KeyEvent(AndroidKey.NUMPAD_0)); worked either.
I found that driver.pressKey(new KeyEvent(AndroidKey.DIGIT_0)); worked. Or in my case, I was inputting a set of numbers from a string, so I used a loop:
for(char c : stringOfDigits.toCharArray()) {
driver.pressKey(new KeyEvent(AndroidKey.valueOf("DIGIT_" + c)));
}
I normally work with C#, but this project is in Java. Hopefully Appium is the same for both languages.
I had simmilar issue on java, so I used two methods for workaround:
1.method
- tap on the textField()
- get pageobject for UIAKeyboard, override numpad keyboard (fetch all buttons into page object)
- used scripted method in pageobject to click on Number element. by name.
2.method
- send keycodes (try using native driver AndroidDriver instead MobileDriver)
3. method
driver.sendkeyEvent(int key);
List Of Key codes:
a - z-> 29 - 54
"0" - "9"-> 7 - 16
BACK BUTTON - 4,
MENU BUTTON - 82
UP-19,
DOWN-20,
LEFT-21,
IGHT-22
SELECT (MIDDLE) BUTTON - 23
SPACE - 62,
SHIFT - 59,
ENTER - 66,
BACKSPACE - 67
or for newer version
driver.pressKeyCode(AndroidKeyCode.HOME);
4. method (didn't tested)
with x,y co-ordinate for each number (0-9 & .) and used driver.tap method

AutoHotKey - Resizing Windows

I currently have a HTPC connected to a plasma in my living room, and I've had a few issues with image retention. While browsing the web, etc. for an extended period of time I'll run into the issue. However, it looks like it should be relatively easy to set up a script with AutoHotKey to resize the window automatically on a timer. Could anyone help me get started on a script to accomplish this task? (Also open to any other ideas)
Thanks!
I created a script quite a while ago that "normalizes" windows, i.e. resizes, moves, and performs other actions to make a window confirm to my personal preference.
Whenever a window displays for the first time, it is normalized. If it is closed and re-opened, it is normalized again.
Below is a functioning version of the script and should satisfy the requirements from the original question.
The version I use is much more complicated because it has many more features, e.g. it supports multiple monitors and resizes windows while taking into account the height of the Windows task bar. I use the script to make open/save dialogs bigger (they are too small by default). I also use it to auto-login to some websites and applications.
; This script "normalizes" windows, i.e. resizes, moves, and performs other
; actions to make a window confirm to my personal preference.
SetTitleMatchMode, 2
; Go into an infinite loop
loop
{
; Pause so other apps can execute. 250 milliseconds seems to work well.
Sleep, 250
; If hotkeys are suspended for this script, then suspend all functionality
if A_IsSuspended
continue
; We will build a unique window name using the window title and window handle.
; Store each unique name in an array.
WinGet, HWND, ID, A
WinGetTitle, WindowTitle, A
WinGetClass, WindowClass, A
; Remember the previous window we processed
WindowTitleCleanPrevious := WindowTitleClean
; Only normalize windows that we haven't seen before.
; If we haven't already normalized the window, we do
; the normalize, then set a flag so we don't normalize the same window again.
; Strip out all chars that may be invalid in an AHK variable name.
WindowTitleCleanTemp := StringRemoveAllNonAlphaNum(WindowTitle)
; Variable names can be at most 254 chars, so truncate to less than that.
StringLeft, WindowTitleClean, WindowTitleCleanTemp, 230
; Process the window if:
; (1) It wasn't previously processed (i.e. not in our window-name list named WinList)
; (2) And we aren't sitting on the same window during each loop.
if (WinList%HWND%%WindowTitleClean% != 1 and WindowTitleClean != WindowTitleCleanPrevious)
{
; Get the window's position and size
WinGetPos, WinX, WinY, WinWidth, WinHeight, A
; Is this an MS Word window?
if (WindowClass == "OpusApp")
{
; Center the window and resize so it is 80% of the monitor width and 90% of height.
WinMove, A, , (A_ScreenWidth/2)-(WinWidth/2), (A_ScreenHeight/2)-(WinHeight/2), A_ScreenWidth * .8, A_ScreenHeight * .9
}
; Is this the Calculator window?
else if (WindowClass == "SciCalc")
{
; Center the window
WinMove, A, , (A_ScreenWidth/2)-(WinWidth/2), (A_ScreenHeight/2)-(WinHeight/2)
}
; Set a flag indicating this window has been processed so it is
; not processed again.
WinList%HWND%%WindowTitleClean% = 1
}
}
; --- Win+F5 will Reload this script ---
~#F5::Reload
; --- Win+Escape will Pause this script ---
~#Escape::Suspend, Toggle
; --- Win+Alt+Escape will Exit this script ---
; Close this script
~#!Escape::ExitApp
; ===========================================================================
; Removes all non-alphabetic and non-numeric characters from the given
; string. The resulting string is returned.
; ===========================================================================
StringRemoveAllNonAlphaNum(SourceString)
{
StringSplit, SplitSourceString, SourceString
OutputString =
Loop, %SplitSourceString0%
{
Char := SplitSourceString%A_Index%
if (Char >= "a") and (Char <= "z")
OutputString := OutputString Char
else if (Char >= "0") and (Char <= "9")
OutputString := OutputString Char
}
return OutputString
}
I am working on the same problem. Here is a script that opens and centers the Windows calculator based of your current screen size. I am still figuring everything out, but maybe this will get you started.
;This script opens and centers the calculator on your screen.
#NoTrayIcon
Run, calc.exe
WinWait, Calculator
WinGetPos,,, Width, Height, %WinTitle%
WinMove, %WinTitle%,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2)
Return
You can resize and snap the window using the below short cuts.
Windows Key + Left Arrow = Window snaps to left side of the screen
Windows Key + Right Arrow = Window snaps to right side of the screen
Windows Key + Up Arrow = Window snaps to upper side of the screen
Windows Key + Down Arrow = Window snaps to lower side of the screen
Windows Key + Up & Left Arrow = Window snaps to upper left corner of the screen
Windows Key + Up & Right Arrow = Window snaps to upper right corner of the screen