I want to make a script which is able to press W in an inactive Minecraft window. So I tried it with "ControlSend". As result I got this:
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance Force
F6::
ControlGet, MC, Selected
return
F7::
ControlSend, %MC%, {Esc Down}, Minecraft* 1.17.1 - Mehrspieler (Drittanbieter-Server) ; sry that the Window title is German
ControlSend, %MC%, {Esc Up}, Minecraft* 1.17.1 - Mehrspieler (Drittanbieter-Server)
ControlSend, %MC%, {w Down}, Minecraft* 1.17.1 - Mehrspieler (Drittanbieter-Server)
return
F8::
ControlSend, %MC%, {w Up}, Minecraft* 1.17.1 - Mehrspieler (Drittanbieter-Server)
return
With this script I can get the window (F6) if I activate it, start pressing W (F7) if Im outside of it and deactivate W (F8) if Im outside. The Problem is, when the Window is inactive Mincraftt goes in the escape screen. Is there a way to tell the Window that it should be active?
Thanks for Helping
Related
I want to make my computer sleep from the command line (DOS, PS, or WSL) in a way so that it wakes up when I click the mouse or press a key - exactly how it works when one clicks "Start -< Power -> Sleep"
The following DO NOT WORK - all of the below put the machine into some other kind of deeper sleep, which ignores keyboard/mouse input (it's a laptop plugged into a monitor - I have to open its lid and press the power button to wake it, which messes up my desktop...)
psshutdown -d -t 0
C:\Windows\System32\rundll32.exe powrprof.dll,SetSuspendState 0,1,0
C:\Windows\System32\rundll32.exe powrprof.dll,SetSuspendState 1,1,0
[Void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") ; $PowerState = [System.Windows.Forms.PowerState]::Suspend; [System.Windows.Forms.Application]::SetSuspendState($PowerState, $false, $false);
(aka)
powershell -Command "[Void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') ; $PowerState = [System.Windows.Forms.PowerState]::Suspend;echo Zzzz;[System.Windows.Forms.Application]::SetSuspendState($PowerState, $false, $false);"
Is there maybe some way to inject key-presses into the windows buffer? This would probably do the trick, if it's possible?:-
Ctrl-Esc, Up-Arrow, Right-Arrow, Right-Arrow, Right-Arrow, Right-Arrow, Enter, Enter
Does the Accessibility subsystem have any easy way to find desktop UI elements (the start menu) and trigger actions on them maybe ? (A click on the "Sleep").
Obviously - the best answer would be if anyone knows exactly what system call windows itself is making when that sleep button is pressed!
I guess this literally answers my question, although it's not ideal (takes a long time, is prone to probably going wrong if keys are pressed in the middle).
powershell - Command "$wshell = New-Object -ComObject wscript.shell;
$explorerpid = Get - Process | Select MainWindowTitle, ProcessName, Id | where {
$_.ProcessNAme - eq 'explorer'
} | foreach {
$_.Id
};
$wshell.AppActivate($explorerpid);
sleep 1;
$wshell.SendKeys('^{ESC}');
sleep 1;
$wshell.SendKeys('{UP}');
sleep 1;
$wshell.SendKeys('{RIGHT}');
sleep 1;
$wshell.SendKeys('{RIGHT}');
sleep 1;
$wshell.SendKeys('{RIGHT}');
sleep 1;
$wshell.SendKeys('{RIGHT}');
sleep 1;
$wshell.SendKeys('{ENTER}');
sleep 1;
$wshell.SendKeys('{ENTER}');
True
The above can be put into a .bat file, or made into a shortcut to make it easier to get to as well.
If anyone knows the correct way to invoke whatever underlying call the explorer.exeprocess is using to trigger a sleep directly, do please let us know!
This is another method which doesn't work for me - might work for others though?
(powershell):-
$PowrProf = Add-Type -MemberDefinition "[DllImport(`"PowrProf.dll`", CharSet = CharSet.Unicode)]`npublic static extern bool SetSuspendState(bool bHibernate, bool bForce, bool bWakeupEventsDisabled);" -Name Kernel32 -Namespace Win32 -PassThru
$PowrProf::SetSuspendState($False, $True, $False) ;echo bForce is not used
From: https://learn.microsoft.com/en-us/windows/win32/api/powrprof/nf-powrprof-setsuspendstate
p.s. The above also shows you how to call arbitrary windows API functions from the command line. Note that the weird things with backticks ` in front of them are powershell escapes for newline `n and quotes `"
Here also is yet-another, which simply does nothing whatsoever for me:-
$Kernel32 = Add-Type -MemberDefinition "[DllImport(`"kernel32.dll`", CharSet = CharSet.Unicode)]`npublic static extern bool SetSystemPowerState(bool fSuspend, bool fForce);" -Name Kernel32 -Namespace Win32 -PassThru
$Kernel32::SetSystemPowerState($True, $False)
Whatever explorer.exe is doing with their "sleep" button is clearly not using any of the above documented APIs - grrr!!
I want to download different apps with a bash script on macOS.
As there are some larger downloads (e.g. Office 365) I would like to include a progress bar in a regular macOS Window.
The applications download+install script looks like this
cd ~/Downloads/ && { curl -O https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg ; cd -; }
sudo hdiutil attach ~/Downloads/googlechrome.dmg
sudo cp -r /Volumes/Google\ Chrome/Google\ Chrome.app /Applications/
diskutil unmount Google\ Chrome
But this does not show any progress for the user (script will run in background).
I found the following example and edited it a bit to my likings
chromedl() {
osascript <<AppleScript
set progress description to "Loading"
set progress additional description to "Please wait"
set progress total steps to 3
repeat with i from 1 to 4
set theSourceCode to do shell script "curl -L -m 30 seconds [url=https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg]https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg]"
set progress completed steps to i
end repeat
display dialog "Progress bar is complete."
AppleScript
But this creates a curl execution error.
Please help me with a functioning Curl Download + Progress Bar script
A basic progress spinner window is easy enough to create using AppleScriptObjectiveC. Copy the following into Script Editor and run it in the foreground (command-control-R, or use the menu command Script→Run in Foreground, which appears when you hold down the control key).
use framework "AppKit"
use AppleScript version "2.4" -- Yosemite 10.10 or later required
use scripting additions
-- convenience properties to make ASOC more readable
property ca : current application
property NSPanel : class "NSPanel"
property NSView : class "NSView"
property NSProgressIndicator : class "NSProgressIndicator"
property NSTextField : class "NSTextField"
property HUD_mask : 8192
property nonactivating_mask : 128
global progress_panel, progress_indicator, label_field
make_progress_panel()
progress_indicator's startAnimation:me
progress_panel's orderFront:me
-- just hang it out there for 5 seconds as proof of concept
delay 5
progress_panel's |close|()
on make_progress_panel()
-- make floating panel
set content_rect to ca's NSMakeRect(200, 800, 140, 80)
set progress_panel to NSPanel's alloc's initWithContentRect:content_rect styleMask:(HUD_mask + nonactivating_mask) backing:(ca's NSBackingStoreBuffered) defer:true
set progress_panel's floatingPanel to true
-- make progress indicator
set progress_rect to ca's NSMakeRect(0, 0, 40, 40)
set progress_indicator to NSProgressIndicator's alloc's initWithFrame:progress_rect
set progress_indicator's indeterminate to true
set progress_indicator's |style| to 1
set progress_indicator's translatesAutoresizingMaskIntoConstraints to false
--make text field
set label_field to NSTextField's labelWithString:"Downloading"
set label_field's translatesAutoresizingMaskIntoConstraints to false
-- make container view, and add subviews
set content_view to NSView's alloc's initWithFrame:content_rect
content_view's addSubview:label_field
content_view's addSubview:progress_indicator
progress_indicator's sizeToFit()
set progress_panel's contentView to content_view
-- view constraints, for alignment
set pi_y_centering to progress_indicator's centerYAnchor's constraintEqualToAnchor:(content_view's centerYAnchor)
set lf_y_centering to label_field's centerYAnchor's constraintEqualToAnchor:(content_view's centerYAnchor)
pi_y_centering's setActive:true
lf_y_centering's setActive:true
set lf_left_margin to content_view's leadingAnchor's constraintEqualToAnchor:(label_field's leadingAnchor) |constant|:-10
lf_left_margin's setActive:true
set pi_left_margin to label_field's trailingAnchor's constraintEqualToAnchor:(progress_indicator's leadingAnchor) |constant|:-10
pi_left_margin's setActive:true
set pi_right_margin to progress_indicator's trailingAnchor's constraintGreaterThanOrEqualToAnchor:(content_view's trailingAnchor) |constant|:10
pi_left_margin's setActive:true
end make_progress_panel
The simplest way to make this work with curl, I think, is to detach the curl process entirely and recover its pid, like so (the code at the end detaches the process and sends the output to oblivion, then returns the pid):
set curl_pid to do shell script "curl -L [url=...] &> /dev/null & echo $!"
Once you have the pid you can set up a loop (or an idle handler, if you create an app) and periodically check to see if the process is still active:
try
set b to do shell script "pgrep curl | grep " & curl_pid
on error
progress_indicator's stopAnimation:me
progress_panel's |close|()
end try
If you want a determinate progress bar, that's easy enough to manage, but you have to figure out a way to measure progress. This link suggests you can get the headers for a file first and extract the file size; you could compare that against the actual on-disk file size as the download progresses, and feed the ratio into the progress bar.
I need to open "Set up Repeat and Slow Keys" in Control Panel through command prompt/PowerShell. But I am not able to do so. Any shortcut or command would be of much help.
Repeat Keys
I can able to open till this point,
Filter Keys
Any help would be much appreciated.
There's no documented shortcut direct to that page. If you need to amend the settings, this can be done through the registry and group policy
Disable Sticky Keys
HKCU\Control Panel\Accessibility\StickyKeys - Flags=506
Disable Filter Keys
HKCU\Control Panel\Accessibility\Keyboard Response] - Flags=122
Disable Toggle Keys
HKCU\Control Panel\Accessibility\ToggleKeys - Flags=58
Or for all NEW users:
Disable Sticky Keys
HKEY_USERS.DEFAULT\Control Panel\Accessibility\StickyKeys - Flags=506
Disable Filter Keys
HKEY_USERS.DEFAULT\Control Panel\Accessibility\Keyboard Response -
Flags=122
Disable Toggle Keys
HKEY_USERS.DEFAULT\Control Panel\Accessibility\ToggleKeys - Flags=58
This PowerShell script should work:
Add-Type -assembly System.Windows.Forms
& control.exe /name "Microsoft.EaseOfAccessCenter" /page "pageFilterKeysSettings"
Do {
Sleep 1
}
while( !(Get-Process | ? { $_.ProcessName -eq 'WindowsInternal.ComposableShell.Experiences.TextInput.InputApp' }) )
[System.Windows.Forms.SendKeys]::SendWait('{Tab 7}')
[System.Windows.Forms.SendKeys]::SendWait('{Enter}')
On Debian 8 installed XRDP + xfce4. There is no possibility to add a new layout to system - the "Add" button is disabled: after logging in go to the "Application Menu - Settings - Keyboard" select "Layout" and see the following picture: see screenshot.
In the directory /etc/xrdp/ there are files:
km-0407.ini
km-0409.ini
km-040c.ini
km-0410.ini
km-0419.ini
km-041d.ini
rsakeys.ini
sesman.ini
startwm.sh
xrdp.ini
km-0419.ini - layout, which I need.
How to add a keyboard layout?
I tried to run inside a terminal session (under root) commands:
setxkbmap
and
xrdp-genkeymap /etc/xrdp/km-0419.ini
In response to the first command I get:
XKB extention not present on: 10.0
second silently executed, nothing happens.
The same commands is a terminal session (on a host-machine) reported:
Can not open display «default display»
and
unable to open display ""
I had a trouble with Debian 9 + xfce + xrdp.
The trouble was the additional layouts disappeared when I reconnected by RDP.
I'm not sure this is exactly you are looking for, I apologize if it is not.
Maybe my experience will help you to figure out how to resolve your trouble.
Also I do not know if it works for your version of xrdp.
For example here is solution for Russian keyboard.
It returns all keyboard layouts settings to default when you start new RDP session.
So there are two ways to resolve it.
Run the command to change your settings to preferable after any RDP login.
setxkbmap -layout us,ru -variant ',winkeys' -option 'grp:alt_shift_toggle,grp_led:scroll'
Or change xrdp config to make it use the settings you want.
What helped me is correcting file /etc/xrdp/xrdp_keyboard.ini
(pay attention for sections [rdp_keyboard_ru] and [layouts_map_ru])
You can use it for another's languages by analogy.
Here is an example of /etc/xrdp/xrdp_keyboard.ini file of mine.
You can see at the end of the file I use my custom sets:
;
; RDP Keyboard <-> X11 Keyboard layout map
;
; How this file works:
; 1. load the file and scan each section to find matching "keyboard_type"
; and "keyboard_subtype" based on the values received from the client.
; If not found, then jump to default section.
; 2. in the selected section, look for "rdp_layouts" and "layouts_map".
; Based on the "keylayout" value from the client, find the right x11
; layout value.
; 3. model/variant are inferred based on the "keyboard_type" and
; "keyboard_subtype", but they can be overridden.
;
;
; RDP Keyboard Type (http://msdn.microsoft.com/en-us/library/cc240563.aspx)
;
; 0 is not a valid value
;
; 1 - IBM PC/XT or compatible (83-key) keyboard
; 2 - Olivetti "ICO" (102-key) keyboard
; 3 - IBM PC/AT (84-key) or similar keyboard
; 4 - IBM enhanced (101- or 102-key) keyboard
; 5 - Nokia 1050 and similar keyboards
; 6 - Nokia 9140 and similar keyboards
; 7 - Japanese keyboard
;
; RDP Keyboard Subtype is vendor dependent. XRDP defines as follows:
;
; 0 is not a valid value
;
; 1 - Standard
; 2 - FreeRDP JP keyboard
; 3 - Macintosh
; ... - < any vendor dependent subtype >
;
; The list can be augmented.
;
; default
[default]
; keyboard_type and keyboard_subtype is not read for default section. It
; is only a placeholder to keep consistency. Default model/variant are
; platform dependent, and could be overridden if needed.
keyboard_type=0
keyboard_subtype=0
; user could override variant and model, but generally they should be inferred
; automatically based on keyboard type and subtype
;variant=
;model=
; A list of supported RDP keyboard layouts
rdp_layouts=default_rdp_layouts
; The map from RDP keyboard layout to X11 keyboard layout
layouts_map=default_layouts_map
[default_rdp_layouts]
rdp_layout_us=0x00000409
rdp_layout_de=0x00000407
rdp_layout_fr=0x0000040C
rdp_layout_it=0x00000410
rdp_layout_jp=0x00000411
rdp_layout_jp=0xe0010411
rdp_layout_jp=0xe0200411
rdp_layout_jp=0xe0210411
rdp_layout_kr=0x00000412
rdp_layout_ru=0x00000419
rdp_layout_se=0x0000041D
rdp_layout_ch=0x00000807
rdp_layout_pt=0x00000816
rdp_layout_br=0x00000416
rdp_layout_pl=0x00000415
; <rdp layout name> = <X11 keyboard layout value>
[default_layouts_map]
rdp_layout_us=us
rdp_layout_de=de
rdp_layout_fr=fr
rdp_layout_it=it
rdp_layout_jp=jp
rdp_layout_kr=kr
rdp_layout_ru=ru
rdp_layout_se=se
rdp_layout_ch=ch
rdp_layout_pt=pt
rdp_layout_br=br(abnt2)
rdp_layout_pl=pl
; if two sections have the same keyboard_type and keyboard_subtype, then
; the latter could override the former.
[rdp_keyboard_mac]
keyboard_type=4
keyboard_subtype=3
rdp_layouts=default_rdp_layouts
layouts_map=rdp_layouts_map_mac
[rdp_keyboard_jp]
keyboard_type=7
keyboard_subtype=2
model=pc105
rdp_layouts=default_rdp_layouts
layouts_map=default_layouts_map
[rdp_layouts_map_mac]
rdp_layout_us=us
rdp_layout_de=de
rdp_layout_fr=fr
rdp_layout_jp=jp
rdp_layout_kr=kr
rdp_layout_it=it
rdp_layout_ru=ru
rdp_layout_se=se
rdp_layout_ch=ch
rdp_layout_pt=pt
rdp_layout_br=br(abnt2)
rdp_layout_pl=pl
[rdp_keyboard_ru]
keyboard_type=4
keyboard_type=7
keyboard_subtype=1
model=pc105
options=grp:lctrl_lshift_toggle,compose:ralt
variant=,
rdp_layouts=default_rdp_layouts
layouts_map=layouts_map_ru
[layouts_map_ru]
rdp_layout_us=us,ru
rdp_layout_ru=us,ru
look at $HOME/.config/xfce4/xfconf/xfce-perchannel-xml/keyboard-layout.xml
setxkbmap -layout us,ru -variant ',' -option 'grp:win_space_toggle'
This popup kills many of my tests. Even simple DOM interactions like .exists? timeout. Is there any way of detecting that it appeared and dismissing it?
Warning: Unresponsive script.
A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete.
dom.max_script_run_time=999
dom.max_chrome_script_run_time=19
These websites aren't designed nor influenced by me. I am merely scraping and sending them instructions as customer.
I run a small autoit3 application that kills popups. If I recall correctly, it waits a little bit to see if the popup is handled before it kills it. This removed many frustrations for me. I also had a version of this that would match certain keywords in the title or body that was read from a file - that allowed me to avoid killing something that needed to stay.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AutoIt Version: 3.1.0 ;
; Author: Dave McNulla ;
; Script Function: Close unwanted popups during test automation. ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
Opt("WinTextMatchMode", 1) ;0=best, 1=quick
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced
Opt("TrayIconHide", 0) ;0=show, 1=hide
Opt("TrayMenuMode", 0) ;0=default
TraySetIcon("Shell32.dll", 98)
dim $SleepTime = 2000
dim $Max = 100
$Message = "{ENTER}"
$ButtonClick = "[CLASS:Button; TEXT:OK]"
$Title = "[CLASS:#32770;TITLE:Internet Explorer]"
While 1
If WinExists($Title) Then
WinActivate($Title)
Sleep($SleepTime)
ControlClick($Title, "", $ButtonClick)
EndIf
Sleep($SleepTime)
If $Max < 1 Then Exit(1)
WEnd