How to exchange mouse button in cuis smalltalk? - 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) ]) ]

Related

How to get the global keydown event in Reflex?

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?

How to send control(key down) to ncurses application via pexpect

I have Linux application written with ncurses. I'm trying to automate it using pexpect but without success.
I can spawn an application and can work with output but I can't send arrow down key:
import pexpect
import time
import sys, os
os.environ['LINES'] = "25"
os.environ['COLUMNS'] = "80"
child=pexpect.spawn("my_ncurses_app", maxread=4000, encoding="utf-8")
child.logfile=sys.stdout
child.setwinsize(25,80)
KEY_DOWN = '\033[B'
#close button appears on screen, After that I want to press down key twice and enter
child.expect("Close")
#ncurses_app sees KEY_DOWN as 3 different keys \033, [, B
child.send(KEY_DOWN)
child.send(KEY_DOWN)
child.sendline()
#ncurses_app sees enter as Int(10)
It works perfect for other CLI applications, but not for my.
Debugging shows what instead of 1 arrow down symbol application sees 3 different keys.
How I can send KEY_DOWN as one symbol? Possibly I should use smth other instead of pexpect, smth with low-level interaction with processes?

AutoIT send() commands not working properly

So I have a game client with 2 input fields: id pass and 1 button: login.
My login credentials are: $id=1234 and $pass=a_bCd.
I'm using AutoIT scripting to automate the login process (my script automatically inputs the id and pass in the login fields) and my AutoLogin() function looks like:
send($id + "{tab}")
Sleep(10)
send($pass + "{enter}")
Sometimes it works fine, but sometimes my script introduces 1234a- or 1234a_ in the ID field and the rest of the characters in the pass field. I tried many solutions like controlsend("Game","","","1234{tab}a_bCd{enter}"), or changing sleep() values, etc. but the input still goes wrong sometimes. Figured the send delay or sleep would have the problem, still don't know what to do.
Manually inserting the id and pass works properly. What would be a good solving of this problem? Thanks
I have had the same troubles with send. This post on autoitscript.com may help you with WinAPI_Keybd_Event() (documentation here):
#include <WinAPISys.au3>
_WinAPI_Keybd_Event(0x11, 0) # Push CTRL down
_WinAPI_Keybd_Event(0x11, 2) # Lift CTRL up again
This helped me with my problems.
NOTE: Sometimes, when your script breaks because of an error, it may happen that one of the keys on your keyboard is still pressed (i.e. pushed down but never lifted up). I use the on-screen keyboard that is integrated in Windows for these moments...
2 Solutions:
You add Strings with &:
send($id & "{tab}")
send($pass & "{enter}")
If that does not work just separate it:
send($id)
send("{tab}")
send($pass)
send("{enter}")
And you don't need that sleep

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)