How can I set TouchScreenKeyboard active to false? - unity3d-2dtools

I have a game in unity where I instantiate a TouchScreenKeyboard:
keyboard = TouchScreenKeyboard.Open(
"", //text
TouchScreenKeyboardType.Default, //type
false, //autocorrect
true //multiline
);
Later, in Update(), I run the following:
keyboard.active = false;
Debug.Log("Turned off keyboard. Now: " + keyboard.active.ToString());
However, in my debugger (running on an iPhone through xcode), I only see:
Turned off keyboard. Now: True
Where it gets really weird: the app does correctly start with the keyboard off on the screen, but if I log keyboard.active it says "True".
When I start the game, the keyboard pops up. However, it doesn't disappear after the game session (where I run keyboard.active = false; again).
If I unfocus the app at this time, however, the keyboard disappears and when I log the status as Debug.Log(keyboard.active.ToString()); it shows false.
What gives? Is this a weird OS interaction? Should I just figure out a way to spoof unfocusing the app, or is there a trick I am missing to make this work? In the example code they use this exact line of code: https://docs.unity3d.com/ScriptReference/TouchScreenKeyboard-active.html
This is unity 2020.2.0f1

Related

Recognizing and Clicking Alert with RSelenium

I'm having some difficulty with an alert I receive during a for loop. Effectively, I can't figure out how to recognize the alert when it comes up and then close it. So far, I've tried this:
if (is.character(mybrowser$getAlertText()) == TRUE) {
mybrowser$acceptAlert
}
I got it to recognize the alert text once, but when I try to use that in the if statement above it doesn't work. For reference, this is what the alert looks like (I'm using Windows 10, I know, I know).
UPDATE: I tried using a try function and it still won't close the alert but hangs instead. When I stop the program and attempt to close the alert in the console with mybrowser$acceptAlert(), it won't recognize the alert and hangs as well. mybrowser$switchToWindow(window) hangs as well. The page appears to be loading while the alert appears. I don't know if that matters.
I noticed you mentioned you've tried try function but alert still be there sometimes. You can try try(mybrowser$acceptAlert(), silent = TRUE) to handle error message instead of detecting your browser receiving an alert or not.
If alert happened, acceptAlert() function would be equivalent to clicking the OK button. If not, try() function would store error messages and handle it.

How to close the popup window which appears during file downloads

In my implementation of the IDownloadHandler interface i have the following in OnDownloadUpdated. The window stays open??
If downloadItem.IsComplete Or downloadItem.IsCancelled Then
browser.CloseBrowser(True)
browser.Dispose()
End If
Must I have this popup window when a download is happening? I have read here I do, if yes how do I close it. I really thought I read in the project issues/comments that the default was now to automatically close it.
Following the comment of amaitland (Thank you) I have my new window closing properly.
For the VB people - here is what I have added to the OnDownloadUpdated event
If downloadItem.IsInProgress = False And browser.IsPopup And browser.HasDocument = False Then
browser.GetHost.CloseBrowser(False)
browser.GetHost.Dispose()
End If

iphone: didUpdateLocations not invoked when testing with the simulator

When debugging my app with the simulator, the routine didUpdateLocations is never involved. What I do:
In the simulator, I select Debug>location>Custom Location and the window with longitude and latitude pops up. When pressing ok, I would expect the didUpdateLocations to be called.
I use locMgr as a global variable in a ViewController-module:
locMgr = CLLocationManager()
and in the viewDidLoad-function includes the following sequence:
locMgr.delegate = self
if CLLocationManager.authorizationStatus() == .NotDetermined {
locMgr.requestWhenInUseAuthorization()
}
I have coded the didUpdateLocations-function as a method of my viewcontroller class. I also verified (debugger), that the requestWhenInUseAuthorization-routine is invoked during initialisation. So were is the problem, why is the didUpdateLocations protocol-routine not invoked?
dasdom solved the problem by suggesting: Why requestWhenInUseAuthorization doesn't prompt the user for access to the location?

PostMessage interferes with user input

I'm trying to send key stroke to an external application in java using jna.
It sends VK_DOWN key, also that application has a shortcut for ctrl+down which makes something very different. My application sends around ~15 down key with 1 sec in between, and if user happens to click CTRL during it while working on a different window, it breaks the application(treats it as ctrl+down).
I checked the keyboard messages via Spy++, compared mine with AutoIt, they are exactly same messages.
ControlSend("window_title", "", "", "{DOWN}")
This AutoIt code works perfect, even if I click ctrl when window is active or inactive, it does not interfere with down key.
My code on the other hand:
User32.INSTANCE.PostMessage(handle, WM_KEYDOWN, wparam, lparamDown);
User32.INSTANCE.PostMessage(handle, WM_KEYUP, wparam, lparamUp);
has exactly same messages, but it doesn't work.
I tried sending control up before sending down key but to no avail.
Spy++ output:
<14335> 00011456 P WM_KEYDOWN nVirtKey:VK_DOWN cRepeat:1 ScanCode:50 fExtended:1 fAltDown:0 fRepeat:0 fUp:0
<14336> 00011456 P WM_KEYUP nVirtKey:VK_DOWN cRepeat:1 ScanCode:50 fExtended:1 fAltDown:0 fRepeat:1 fUp:1
My ctrl clicks are not even on target application so why does it treat it as such? Should I use a hook?

How to test a confirm dialog with Cucumber?

I am using Ruby on Rails with Cucumber and Capybara.
How would I go about testing a simple confirm command ("Are you sure?")?
Also, where could I find further documentation on this issue?
The selenium driver now supports this
From Capybara you would access it like this:
page.driver.browser.switch_to.alert.accept
or
page.driver.browser.switch_to.alert.dismiss
or
page.driver.browser.switch_to.alert.text
Seems like there's no way to do it in Capybara, unfortunately. But if you're running your tests with the Selenium driver (and probably other drivers that support JavaScript), you can hack it. Just before performing the action that would bring up the confirm dialog, override the confirm method to always return true. That way the dialog will never be displayed, and your tests can continue as if the user had pressed the OK button. If you want to simulate the reverse, simply change it to return false.
page.evaluate_script('window.confirm = function() { return true; }')
page.click('Remove')
I've implemented these two web steps in /features/step_definitions/web_steps.rb:
When /^I confirm popup$/ do
page.driver.browser.switch_to.alert.accept
end
When /^I dismiss popup$/ do
page.driver.browser.switch_to.alert.dismiss
end
If you want to specifically test the message being displayed, here's a particularly hacky way to do so. I don't endorse it as beautiful code, but it gets the job done. You'll need to load http://plugins.jquery.com/node/1386/release, or change it to do cookies natively if you don't want jQuery.
Use this sort of story:
Given I am on the menu page for the current booking
And a confirmation box saying "The menu is £3.50 over budget. Click Ok to confirm anyway, or Cancel if you want to make changes." should pop up
And I want to click "Ok"
When I press "Confirm menu"
Then the confirmation box should have been displayed
And these steps
Given /^a confirmation box saying "([^"]*)" should pop up$/ do |message|
#expected_message = message
end
Given /^I want to click "([^"]*)"$/ do |option|
retval = (option == "Ok") ? "true" : "false"
page.evaluate_script("window.confirm = function (msg) {
$.cookie('confirm_message', msg)
return #{retval}
}")
end
Then /^the confirmation box should have been displayed$/ do
page.evaluate_script("$.cookie('confirm_message')").should_not be_nil
page.evaluate_script("$.cookie('confirm_message')").should eq(#expected_message)
page.evaluate_script("$.cookie('confirm_message', null)")
end
Updating this for current releases of Capybara. Most Capybara drivers today support the modal API. To accept a confirm modal you would do
accept_confirm do # dismiss_confirm if not accepting
click_link 'delete' # whatever action triggers the modal to appear
end
This can be used in Cucumber with something like
When /^(?:|I )press "([^"]*)" and confirm "([^"]*)"$/ do |button, msg|
accept_confirm msg do
click_button(button)
end
end
which will click the named button and then accept a confirm box with text matching msg
The capybara-webkit driver supports this as well.
Scenario: Illustrate an example has dialog confirm with text
#
When I confirm the browser dialog with tile "Are you sure?"
#
=====================================================================
my step definition here:
And(/^I confirm the browser dialog with title "([^"]*)"$/) do |title|
if page.driver.class == Capybara::Selenium::Driver
page.driver.browser.switch_to.alert.text.should eq(title)
page.driver.browser.switch_to.alert.accept
elsif page.driver.class == Capybara::Webkit::Driver
sleep 1 # prevent test from failing by waiting for popup
page.driver.browser.confirm_messages.should eq(title)
page.driver.browser.accept_js_confirms
else
raise "Unsupported driver"
end
end
Prickle adds some handy convenience methods for working with popups in selenium and webkit
This gist has steps to test a JS confirm dialog in Rails 2 and 3 with any Capybara driver.
It's an adaptation of a previous answer, but doesn't need the jQuery Cookie plugin.
Tried the above answers with no luck. In the end this worked for me:
#browser.alert.ok

Resources