How to get the global keydown event in Reflex? - ghcjs

My current attempt at getting an event of global keypress (eg: user hits a keyboard shortcut, from anywhere in the UI, to trigger opening of modal dialog) is:
prerender_ blank $ do
-- ctx <- askJSM
doc <- currentDocumentUnchecked
win <- currentWindowUnchecked
let clicked = traceEvent "hit" $ keydown Enter win
widgetHold_ (text "Waiting") $
ffor clicked $ \() -> do
text "CLICKED"
However, this fails to typecheck
• Could not deduce: DomEventType JSDOM.Types.Window
'KeydownTag ~ Word arising from a use of ‘keydown’
Looking at the source, only Element EventResult d t has an instance, but not Window or Document.
What is the idiomatic way to achieve what I'm trying to do here, in reflex / ghcjs?

Related

How can I reverse "action.KeyDown(Keys.Alt).SendKeys("N").Perform();" in C#, Seleium/Appium/Visual Studio

I am testing uploading from file explorer window that has been opened via web browser application - for some reason it can find the open window but can't find File name field and doesn't actually click the Open button (despite passing that step).. As a result I have had to use alt + N to select the File name field, which is all well and good, but that results in disabling my keyboard for all other apps.
I presumed that I would only need to do a KeyUp on the alt button as there is no equivalent for the N key, which is obviously sent using SendKeys method... The code below DOES run, but it is far from ideal if I'm going to have to keep coding key strokes that I can't reverse unless manually...
if (open != null)
{
Actions action = new Actions(session);
session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
Thread.Sleep(1000);
action.KeyDown(Keys.Alt).SendKeys("N").Perform();
action.KeyUp(Keys.Alt).SendKeys("19th December 1932 (2).xlsx").Perform();
action.KeyDown(Keys.Alt).SendKeys("o").Perform();
action.KeyUp(Keys.Alt).Perform();
Does it work if you write the actions like this?
action.KeyDown(Keys.Alt).SendKeys("N").KeyUp(Keys.Alt).SendKeys("19th December 1932 (2).xlsx")Perform();
action.KeyDown(Keys.Alt).SendKeys("o").KeyUp(Keys.Alt).Perform();

Roku How to get standard input in Main.brs

I am writing a Roku application and I need to read a string from the standard input. I am aware that to print to the standard output I can use the function print, but I need to give to the user the launches the script the possibility to insert new parameters at run time, for example (pseudo-code):
print "Enter server IP: "
string ip = getline();
print "Server IP " + ip
Is there a way to do it?
You would need to add Keyboad*** component to your Scene.xml file:
<Keyboard
id = "keyboard"
/>
After that add a Button component in Scene.xml, declare it in Scene.brs - init() function and set observer field on "buttonSelected".Also declare keyboard and set focus on it:
init() :
m.keyboard = m.top.findNode("keyboard")
m.keyboard.setFocus(true)
m.button = m.top.findNode("button")
m.button.observeField("buttonSelected","onButtonSelected")
Then create a Sub to get a user input from Keyboard when button is pressed:
Sub onButtonSelected()
print m.keyboard.textEditBox.text
End Sub
***Note that Keyboard component has TextEditBox build in so you don't have to add it manually in Scene.xml file.
There is no "standard input" concept in Roku development. There are a few way your code can take external input though.
One is as mentioned above by #U-Mitic - to use component with keyboard input from the remote control, like roKeyboardScreen or KeyboardDialog RSG node and the like.
Another is to send such information externally over http by using ECP (Roku's External Control Protocol) - either /input or /launch w/params

How to exchange mouse button in cuis smalltalk?

I'd like to exchange button usage in Cuis smalltalk.
Currently the right mouse button brings up the alo, while the middle button shows the context menu.
Is it possible to switch such behaviours ?
You can change the ButtonDecodeTable in the image, or you can tell the VM to use a different mouse mapping. This depends on the platform:
Windows: toggle 3ButtonMouse setting in the VM's *.ini file, either by pressing F2 or manually, see http://squeakvm.org/win32/settings.html
Unix: pass a command line argument -swapbtn
Mac: edit the button mapping in Info.plist
Ok, I've found it.
It seems that in the method installMouseDecodeTable
I need to swap the DecodeTable bits even on Windows
(I'm working on windows 7, and the buttons are swapped)
"Create a decode table that swaps the lowest-order 2 bits if not on Windows.
This is to make right mouse button be the mouseButton2, i.e. open menus, and middle (wheel) button open halos (mouseButton3).
See #processEvent:"
If I force the switch, swapping the bits, (for example using a dummy platformname, or removing the test altogether), then the buttons work correctly.
(You need to save the image, close and reopen the program)
ButtonDecodeTable _ Smalltalk platformName = 'Dummy'
ifTrue: [ ByteArray withAll: (0 to: 255) ]
ifFalse: [
ByteArray withAll:
((0 to: 255) collect: [ :ea |
((ea bitAnd: 1) << 1 bitOr: (ea bitAnd: 2) >> 1) bitOr: (ea bitAnd: 252) ]) ]

ControlClick not working with AutoItX3

I am currently trying to use AutoItX3 to do some automation.
My script opens up an application and now I want it to click on the certain button within the app. This is my code for the ControlClick (parameters were acquired from the AutoIt v3 Window Info Tool) :
Local $sText = WinGetTitle("[ACTIVE]")<br>
ControlClick($sText, "", "[CLASS:WindowsForms10.Window.8.app.0.33c0d9d; INSTANCE:62]", "left", 1, 21, 12)
Unfortunately, this code does not seem to do anything at all. I replaced it with a regular mouse click with coordinates, but then this script won't work on any computer with a different resolution.
Any ideas?
Try this to understand what I meant.
Example()
Func Example()
; Run Notepad
Run("notepad.exe")
; Wait 10 seconds for the Notepad window to appear.
WinWaitActive("[CLASS:Notepad]", "", 10)
ControlSetText("[CLASS:Notepad]", "", '', 'HELLO WORLD!')
; Wait for 2 seconds to display the Notepad window.
Sleep(2000)
ControlSend("[CLASS:Notepad]", "", '', '{Right 20}{ENTER}NEW LINE!')
; Close the Notepad window using the classname of Notepad.
WinClose("[CLASS:Notepad]")
WinWaitActive("Editor", "", 10)
ControlSend("Editor", "", '', '!n')
EndFunc ;==>Example
Are you sure that AutoIt spy tool identifies the button individually?Some times AutoIt info tool identifies a some portion of a application(multiple buttons or multiple tabs)as single object.In that situation you have to use the mouseclick opration and after that use control click function like below
mouseclick("",21,21)
Controlclick("","","button1",21,21)
this might help you.make sure to capture the x and y coordinates from the Mouse tab of autoIt info tool.
Sometime it could happend on some windows protected with an anti-bot/macro systems such as games, java clients etc...
You could by-pass this using a VM with a third-party desktop controler such as teamviewer/RDP/... You will be able to run your script thru the RDP session.
Please Note: AutoIt is not made to make GameBots :)
Vlu.

Python 3 - How to input data without pressing <return> in OSX

I am attempting to move a character using the "asdw" keys in a game, but I cannot find a way to constantly input data without pressing return. I have seen that on windows there is a module called msvcrt, which has a getch function, so I am wondering if there is a way to simulate this in OSX, or more simply to just constantly input data from the keyboard.
Try the curses library:
http://docs.python.org/py3k/library/curses.html
Curses is a library for controlling the terminal, and includes features such as drawing box shapes as well. It's available on any POSIX-compatible system, which includes Mac OS X and GNU/Linux.
Here's an example:
import curses
import time
# Turn off line buffering
curses.cbreak()
# Initialize the terminal
win = curses.initscr()
# Make getch() non-blocking
win.nodelay(True)
while True:
key = win.getch()
if key != -1:
print('Pressed key', key)
time.sleep(0.01)
You can use Turtle to do something like this:
import turtle
Sc = turtle.Screen()
Sc.setup(width=0, height=0) #this hides turtle's windows
def a(): #that's the function that you want to run when the key is pressed
#code here
Sc.listen() #this tells the program to listen
for a keypress
Sc.onkey("#The key here", #the function call here) #this tells the program
What function to call when a certain key is pressed
# An example of pressing the key "w"
Sc.onkey("w", a)