Create a script in Windows 7 that controls volume - windows

I'm relatively new to programming and I want to make a script that controls the volume of my pc, linkt to hotkeys. What I want it to do specifically is whenever I press a key on my keyboard (i.e. ctrl + Alt + arrow up), it turns the volume to 75% and when I press another key (i.e. ctrl + Alt + arrow down), it turns it to 15%.
What type of script would I need to make, where shoult it be saved and how do I setup a hotkey to trigger it? (Also, I want this to work as soon as my pc boots up, or right thereafter). You don't need to prewrite a script for me, just point me in the right direction and I'll find my way.
This is what I've got so far:
; Volume control (turn master volume to 75% or 15%)
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
^!F12::Soundset, 75
^!F11::Soundset, 15
This works fine, but I use it on a laptop, which also has a function (fn) key to in-/decrease volume and mute it. Now, whenever I mute using the function key, I cannot set de volume to 75% with the hotkey. So I was wondering if I could override the function key (or whenever I press ctrl + fn + volume up/down it sets it to 75%, or 15%, respectivily). Also the script doesn't give any visual feedback, apart from the volume icon showing more or less volume bars (or however it's called). How would I go about doing this?
ALso, do I need those first few lines (e.g. #NoEnv, #Warn,...) or are they just for failsafe?
Any help would be much appreciated.

Look at the link in 2501's comment first. Try some things for yourself.
Then look here: https://autohotkey.com/docs/commands/SoundSet.htm which will tell you about SoundSet. Then try some more things yourself.
SoundSet
Changes various settings of a sound device (master mute, master volume, etc.)
SoundSet, NewSetting [, ComponentType, ControlType, DeviceNumber]
NewSetting: Percentage number between -100 and 100 inclusive (it can be a floating point number or expression). If the number begins with a plus or minus sign, the current setting will be adjusted up or down by the indicated amount. Otherwise, the setting will be set explicitly to the level indicated by NewSetting.

Related

How to Zoom in /out in emacs -nw (command line only) whithout having a numeric keypad (also without mouse wheel)?

I am having trouble finding the shortcut for Zooming (increasing font size) / unZooming (decreasing font size) in emacs. I must add that I am interested in the command-line emacs (i.e. no window, i.e. "-nw" option) only, I don't use the graphical interface.
The Zoom-in command is supposed to be C-x C-+ and the Zoom-out C-x C--, also since I am using a laptop - often without mouse -, I am not interested by a "mouse-wheel up/down" option.
I tried C-x C-+ in two ways:
"typing Ctrl then 'x' then Ctrl then key '1' which is the key with the '+' symbol above the 1 on my qwertz keyboard"
"typing Ctrl then 'x' then Ctrl - WHILE HOLDING SHIFT" then key '1' which is the key with the '+' symbol above the 1 on my qwertz
keyboard"
neither seem to work, although the second would seem to make more sense, i.e. to hold shift as if to write the '+' sign that i can get with shift-'1'
So I wonder: is the shortcut C-x C-+ only intended for people equipped with a numeric keypad ? or is there another way and in any case what do you suggest ?
And no, this question (How do I bind C-= in emacs?) does not answer mine, in fact I don't even understand what it is about (question is totally unclear and unrelated to mine - as far as i understand)...
I am just asking how to Zoom/unZoom i.e. increase/decrease font size...
Since emacs is running within a terminal, you can't directly control the font as you would running as a GUI app. To zoom in and out, you need to use the method that your terminal application provides for changing the font size. This is often <ctrl>+ and <ctrl>-, but your terminal keybindings may be different.

Selective keyboard failure windows 10

the following keys function normally: escape, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, prtsc, delete, home, end, pgup, pgdn, backspace, numlock, tab, capslock, enter, shift, ctrl, fn, windowskey, alt, left arrow, up arrow, down arrow, right arrow, ins
additionally all keyboard shortcuts function, which means it must be able to sense the rest somehow but seemingly ignores them when typing
it seems to be anecdotally linked to postponing a pending update; as it has happened three times and each time i have eventually given up and attempted a reboot only to see the update install itself and the problem vanish??
i have tried using a usb keyboard and the same issues apply.
the onscreen keyboard bypasses the problem but obviously can't be considered anything like a real solution, it does at least let me save my work(though i'd hate to type more than a sentence with it) and run simple tests.
i have not made any notable hardware or software changes in the recent past, nothing can be linked to this suddenly appearing that i am aware of.
anecdotally, the problem hasn't been seen to occur until the computer has been on and in use for some amount of time, having annoyingly and potentially disastrously(i wasn't doing anything important yet but it's only a matter of time until it happens while i'm in some timed test or need to submit something online rather than just save it to wordpad) appeared only when I am in the middle of something, though again no common link i can think of(once while simply browsing internet(chrome), once when typing an essay in wordpad with airplane mode on and all other windows closed, once while playing a game on steam).
I'd estimate that I properly shut down my computer roughly once a week (if not more often) so it doesn't feel like it should be an uptime issue? (seems to appear a few hours into that specific use of the computer, though this is often having turned it on from hibernation or even sleep so not sure where to start counting)
what it is not: windows key stuck (physically or otherwise), any keyor set of keys physically stuck, stickykeys, togglekeys, etc.
(the shortcuts do not happen unless I actually press winkey/ctrl/etc, otherwise pressing a button simply leads to nothing. eg p does nothing, ctrl lights up on the onscreen keyboard, ctrl+p prints)
am using an hp laptop
edit- 6/11: happened again, and again there was a pending windows update downloaded and waiting for permission to restart. i last turned my computer off three days ago and the keyboard didn't stop working until about 8 hours after i used pro to delay the update's mandatory restart by one week (upon restarting to fix the keyboard it of course took the opportunity to install said 'delayed' update despite this)

Fast text scrolling in VS Code

I am testing out Visual Studio Code on macOS, and was wondering if there is a key combination for faster scrolling?
I would need this, for example, to go quickly from an early part of the code to a part towards the end of the file.
e.g. in Emacs when I hold up/down-arrow and hit Ctrl, the scroll speed increases noticeably; VS Code actually stops scrolling with the same command. Cmd+arrow will get me to the start / end of the file, but I could not find a combination that merely speeds things up and nothing in the keyboard shortcuts looked helpful.
Version is 1.21.1.
Update: Since v1.31 you can now press Alt to enable fast scrolling. It works by activating editor.fastScrollSensitivity.
There is
"editor.mouseWheelScrollSensitivity": 1, // or any number
You can scroll by pages too:
PageDown or PageUp
Go to File > Preferences > Settings. Search for: mouseWheelScrollSensitivity, change it for 0.01
in Emacs when I hold up/down-arrow [...]
The OP mentioned key strokes as opposed to mouse scrolling.
My solution was at an OS level, i.e. lessen the Key Repeat and Delay Until Repeat settings so that holding the up / down arrows will scroll much quicker.
Important note: This setting will update all key presses regardless of the app.
If on OSX, this setting can be found in System Preferences under Keyboard, or overwritten directly in the terminal. The following will take effect after a system reboot.
defaults write -g InitialKeyRepeat -int 10 # normal minimum is 15 (225 ms)
defaults write -g KeyRepeat -int 1 # normal minimum is 2 (30 ms)
It is not available, but is an open issue. You can follow the progress here:
https://github.com/Microsoft/vscode/issues/24344

Getting "complete" and "menu-complete" to work together

I found out that the Bash shell supports a type of autocompletion that is different from the "traditional" autocompletion, where all possibilities get listed on the following line.
With the "traditional" autocompletion, if I type ch and then press the Tab key, I get something like:
$ ch
chacl chgrp chmod chown chvt
But if I add the following line to my /etc/inputrc (which remaps the Tab key to the built-in menu-complete function):
Tab: menu-complete
then the behavior of the shell changes: the word to be completed is replaced "inline" with a single match from the list of possible completions, and if I press the Tab key again, the word gets replaced with the next match.
I found this useful, but I still wanted to keep the traditional autocompletion and have it bound to the key combination Ctrl + Tab. So I added the following line to my /etc/inputrc file, according to what the readline library documentation suggests:
Ctrl-Tab: complete
However, adding this line only seems to make both Tab and Ctrl-Tab call the traditional complete function.
Does anyone know what I am doing wrong?
Thanks in advance!
To start with, I'm not a massive expert in this area, but I think I can answer your question. First of all, while you are using Bash, Bash is a shell which interprets keyboard commands that it receives from a terminal / console. While you are informing Bash how to react to specific key combinations in the inputrc file, your Terminal determines precisely which character is 'sent' to the Shell before the inputrc file even enters the equation.
Unfortunately, on my system (granted, it's OSX - but I don't think this is strange behaviour when compared to Linux), both Tab and Ctrl-Tab send the same keyboard input to the shell. Infact, both Tab and Ctrl-Tab send a Ctrl-I command to the shell, and indeed, if I enter Ctrl-I when using the terminal, it performs the completion as if I hit Tab.
The software (installed on most Linux systems by default), showkey will tell you what keys the shell is receiving when you press specific keyboard inputs as you push them.
Anyway, my suggestion to you is to use Shift-Tab, which does appear to send it's own key-code to the shell. Shift-Tab on my computer shows up (using showkey) as '<ESC>[Z', which I think is pretty standard across the board. As such, your inputrc file with the following bindings should allow you to use shift-tab instead of ctrl-tab to achieve what you desire:
Tab: menu-complete
"\e[Z": complete
The \e in the second binding represents the escape character, and the [Z are simply the characters as shown using showkey. You can get a similar effect on OSX by simply using cat, running cat from within a terminal and pressing Shift-Tab will show you "^[[Z", where ^[ represents the escape character and the other characters are as before.
I know this doesn't resolve your question precisely, but as I don't think you are able to use Ctrl-Tab as a key combination, without re-mapping Ctrl-Tab to another keybinding within your terminal (more likely to be easier if you are using a GUI terminal), this is likely as close as you can get without significant effort!
I have ShiftTab bound to menu-complete-backward, so it goes back one step if I skipped the right completion, and I've mapped Ctrlq to complete, so if there are several possible completions I hit Ctrlq to list them without having to cycle through them.
# Make Tab cycle between possible completions
# Cycle forward: Tab
# Cycle backward: Shift-Tab
TAB: menu-complete
"\e[Z": menu-complete-backward
# Make C-q display the list of possible completions
Control-q: complete
# Display the list of matches when no further completion is possible
set show-all-if-unmodified on
Edit: Ctrlq is bound to quoted-insert by default, that is, it tells the shell to take the next key literally. quoted-insert is also bound to Ctrlv, so you don't lose that functionality if you rebind Ctrlq. Anyway, I've found that AltESC also works, by default, for showing the possible completions (as far as I can tell it is equivalent to TAB); note that it may be seized by Gnome, then either double press ESC or rebind "Switch windows directly" in Settings → Devices → Keyboard → Navigation.
The following should achieve what you're looking for (if I understand correctly!)
In your .inputrc
# display all possible matches for an ambiguous pattern at first tab
set show-all-if-ambiguous on
# next tab(s) will cycle through matches
TAB: menu-complete
# shift tab cycles backward
"\e[Z": menu-complete-backward
Where to start, if you can or cant do this is dependent your keyboard and your drivers and there isn't one catch all answer. Each key press and release generates a sequenced key pair (key down and release) (scancode) these codes are then translated by the kernel into keycodes for example on my laptop keyboard 0x3a 0xba are translated to keycode 15 (down and up) these are then translated into actions such as return letter c a / you can assign actions to keysyms using the keycode/hex/binary/octal notation which codes match which letters is determined by the kernel translation table which is fairly standardized, however the first part signal that's translated to keycodes is different for most keyboards.
Continuing with the earlier example for me shift tab (and alt and control and any combination) produce keycode 15 however in hex it produces 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a and this is because shift alt and control are special keys (modifiers) these multiply out against the keycodes and fill out the dumpkeys table the kernel is limited to the number of assignments as well this is determined by your choice of keymap and shares resources with your terminal colors (if your char set its defined above the threshold it limits your terminal color scope). And this all goes out the window if your in an xserver and has a whole new system. Most of these things can be changed,modified and manipulated by the user and programs installed. My point to all this is to emphasize that there is no catch all for the mapping of the tab key and its going to vary keyboard drivers to kbd drivers (now if you find a solution that happens to work for you excellent :)) but chances are it won't be portable and might not work if you change keyboards and might not translate between xserver and tui. What i recommend is learning the steps to modify your kbd on the go.
will give you the decimal octal hex notation for a key press on the same line
--full-table -1 >> keytable
will give you a documented with your full list of keycode->keysym pairing in a format that will give you a better picture of your layout and from there you can either use loadkey to change a keys value or ad an entry in .inputrc or your main rc file. You can also create a custom key.map file.
Further escape sequence translation is determined by the "$TERM" variable and each virtual terminal emulator can be different
infocmp "$TERM"
will give you a list of your terminal escape sequences
Resources:
https://man7.org/linux/man-pages/man4/console_codes.4.html
https://www.gnu.org/software/screen/manual/html_node/Input-Translation.html
http://kbd-project.org/docs/scancodes/scancodes.html
https://www.vt100.net/
So to sum up.
Your keyboard drivers
Your kemap choice
Your virtual terminal emulator
and your kernel
form the backbone of remapping dificult keys (tab/s-tab/a-tab)
I'm not sure Ctrl-Tab is a real character; my terminal, for instance, ignores the combination. I think the only way to use Ctrl-Tab is to use your terminal emulator to map it to some otherwise unused escape sequence, then bind that sequence to complete.

Remap Caps lock key to Esc in Mma 7

TLDR: How do I get CapsLock to translate to "ShortNameDelimiter" in Mma 7?
I like pretty text in my mma notebooks, and often define functions as f[\[Alpha]_] =... so as to match the exact equation that I'm working with. As such, it involves a lot of Esc-letter-Esc sequences, and reaching for Esc every other stroke breaks my flow of typing.
Now, the CapsLock key is seldom used (I can't remember the last time I needed it), but conveniently placed (your pinky is right there!). Remapping it to Esc on vim worked wonders for me and I was wondering if there was a way to do the same in mma, without having to modify the system's keyboard layout.
I tried editing KeyEventTranslations.tr by adding the following in EventTranslations[{...
Item[KeyEvent["CapsLock"], "ShortNameDelimiter"]
but that had no effect. Is there another way to do it? Is CapsLock not the correct identifier? If it helps, I'm using Mma7 student version on a Mac.
Modifier keys are handled quite specially, and I doubt Mathematica will be able to override the system. You probably have to do this in a layer between Mathematica and the OS. BUT, it is possible to make the key behave different depending on the application you are in. Thus with a bit of work, it MAY be possible to have the capslock key behave differently only in Mathematica.
edit: I did not see you say which operating system you had, so I've added Mac instructions.
Windows
For example, if you have Windows, you can use the program called http://www.autohotkey.com/ . It specifically has a feature where you can bind a key to a script, specifically the following script:
How can a hotkey or hotstring be made exclusive to certain program(s)?
In other words, I want a certain key to act as it normally does except when a specific window is active.
In the following example, NumpadEnter is made to perform normally except when a window titled "CAD Editor" is active. Note the use of the $ prefix in "$NumpadEnter", which is required to let the hotkey "send itself":
$NumpadEnter::
IfWinNotActive, CAD Editor
{
Send, {NumpadEnter}
return
}
; Otherwise, the desired application is active, so do a custom action:
Send, abc
return
This next example is more pure than the above, but it will only work if the "CAD Editor" application is designed to ignore the NumpadEnter key itself. The tilde prefix (~) makes NumpadEnter into a non-suppressed hotkey, meaning that the NumpadEnter keystroke itself is always sent to the active window, the only difference being that it triggers a hotkey action. The ~ feature requires Windows NT/2k/XP.
~NumpadEnter::
IfWinNotActive, CAD Editor
return
; Otherwise, the desired application is active, so do a custom action:
Send, abc
return
To quote from "MRCS" in this forum post, you may find the following useful:
The first one I named CapsLockR.ahk and contains the following script:
CapsLock UP::Run C:\Documents and Sett...[path to script]...\CapsLock.ahk
The second one is named CapsLock.ahk and has this script:
GetKeyState, state, CapsLock, T
if state = D
SetCapsLockState, off
else
SetCapsLockState, on
exit
Thus worse comes to worst, if you are having trouble modifying the "Behave like Foo if Active Window = Mathematica else behave like Bar" script, you can tack on this to manually toggle the CapsLock state I think. Googling will also reveal more results.
Linux
I know that on Linux, you can use the program called xbindkeys to bind the CapsLock to a script, from which you can in turn call xdo if you detect Mathematica is one of the topmost windows (e.g. via Getting pid and details for topmost window , or xdotool getwindowfocus) or worse-comes-to-worst, you can just have a script which toggles your configuration between CapsLock -> xdotool key Escape, xdotool type "whatever", xdotool key Escape ("Mathematica mode") and "normal mode"... though that may prevent you from YELLING AT MATHEMATICIANS OVER INSTANT MESSAGING WHILE DOING MATHEMATICS. Unless you You may need to find some way to programatically toggle CapsLock, perhaps by creating a dummy CapsLock key (though that's an extreme hack, it is likely one can find some kind of library; perhaps Anybody know how to toggle caps lock on/off in Python? may be useful). (This issue could be avoided by using a key besides CapsLock, or not caring that you want to keep your CapsLock functionality; you could also just turn another key you never use into CapsLock.)
Mac
Mac may have similar tools. For example, you can get xdotool like on Linux above via the MacPorts project. I hear the CapLock key cannot normally be rebound as easily on Mac, so if you can deal with another key it may be much easier. But theoretically it should be possible...
If you wish to use CapsLock, you can use PCKeyboardHack http://pqrs.org/macosx/keyremap4macbook/extra.html to remap the CapLock key to something which will tell OS X to let you remap the CapsLock. Then you remap it, then bind the key using Quicksilver to a script that makes calls xdotool to check if you're in Mathematica also also to issue the :esc:...:esc: if you are (see the Linux section of this answer). Otherwise you simulate a keypress on the CapsLock. But you remapped CapsLock! So you might need to make another dummy key you never use into the CapsLock key, and trigger a keypress on that using Cocoa libraries or a simple AppleScript. If you wish to pursue the CapsLock route, you might find Using Caps Lock as Esc in Mac OS X useful.

Resources