I'm using an apple keyboard with windows 7. I'd like the function keys labelled with 'media' functions (prev, pause/play, next, mute, vol-, vol+) to work like the equivalent keys on a windows keyboard.
I've tried this autohotkey script:
F7::Media_Prev
F8::Media_Play_Pause
F9::Media_Next
F10::Volume_Mute
F11::Volume_Down
F12::Volume_Up
Looking at the key history the keys seem to be remapped as expected, but they don't have any effect.
A working (i.e. all keys work as expected and trigger the appropriate media function) windows media keyboard looks like this:
VK SC Type Up/Dn Elapsed Key Window
------------------------------------------------------------------------------------
B3 122 a d 32.79 Media_Play_Pause
B3 122 a u 0.14 Media_Play_Pause
B2 124 a d 0.61 Media_Stop
B2 124 a u 0.17 Media_Stop
AF 130 a d 0.58 Volume_Up
AF 130 a u 0.17 Volume_Up
AE 12E a d 0.42 Volume_Down
AE 12E a u 0.16 Volume_Down
B1 110 a d 0.87 Media_Prev
B1 110 a u 0.14 Media_Prev
B0 119 a d 0.30 Media_Next
B0 119 a u 0.11 Media_Next
AD 120 a d 1.56 Volume_Mute
AD 120 a u 0.13 Volume_Mute
Using the script referenced above I see this from the apple keyboard:
VK SC Type Up/Dn Elapsed Key Window
------------------------------------------------------------------------------------
B1 010 i d 0.00 Media_Prev
76 041 h u 0.09 F7
B1 010 i u 0.00 Media_Prev
77 042 h d 0.20 F8
B3 022 i d 0.00 Media_Play_Pause
77 042 h u 0.08 F8
B3 022 i u 0.00 Media_Play_Pause
78 043 h d 0.20 F9
B0 019 i d 0.00 Media_Next
78 043 h u 0.09 F9
B0 019 i u 0.00 Media_Next
79 044 h d 0.22 F10
AD 020 i d 0.00 Volume_Mute
79 044 h u 0.09 F10
AD 020 i u 0.00 Volume_Mute
7A 057 h d 0.19 F11
AE 02E i d 0.00 Volume_Down
7A 057 h u 0.09 F11
AE 02E i u 0.00 Volume_Down
7B 058 h d 0.65 F12
AF 030 i d 0.00 Volume_Up
7B 058 h u 0.08 F12
AF 030 i u 0.00 Volume_Up
Any idea why this isn't working?
Check if this script works:
It basically maps keys of your choice to next, previous, play and pause.
So, you can map those function keys labeled with media functions.
about volume controls, I'll look for it.
;
;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Windows 7
; Author: Brian Kamrany
;
; Script Function: Control iTunes, Windows Media Player, and Winamp easily.
;Numpad Subtraction = next
;Numpad Multiplication = previous
;Numpad Division = pause/unpause
;Note: if you want to change the hotkeys to numpad numbers, you must add
;both the numpad number and it's alternate key.
;For example
;Numpad6::
;NumpadRight::
;(written like that) are both needed if you want to use 6 on the numpad as your hotkey
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
DetectHiddenWindows, on
NumpadSub::
if WinExist("ahk_class ITWindow") or WinExist("ahk_class iTunes")
{
ControlSend, ahk_parent, ^{RIGHT}
}
IfWinExist, ahk_class WMPlayerApp
{
SetKeyDelay, 0, 1 ;otherwise doesn't work if currently in WMP window
ControlSend, ahk_parent, ^{f}
}
IfWinExist, ahk_class Winamp v1.x
ControlSend, ahk_parent, b
return
NumpadMult::
if WinExist("ahk_class ITWindow") or WinExist("ahk_class iTunes")
{
ControlSend, ahk_parent, ^{LEFT}
}
IfWinExist, ahk_class WMPlayerApp
{
SetKeyDelay, 0, 1
ControlSend, ahk_parent, ^{b}
}
IfWinExist, ahk_class Winamp v1.x
ControlSend, ahk_parent, z
return
NumpadDiv::
if WinExist("ahk_class ITWindow") or WinExist("ahk_class iTunes")
{
ControlSend, ahk_parent, ^{SPACE} ;control for better grip, otherwise doesn't work if were filtering songs
}
IfWinExist, ahk_class WMPlayerApp
{
SetKeyDelay, 0, 1
ControlSend, ahk_parent, ^{p}
}
IfWinExist, ahk_class Winamp v1.x
ControlSend, ahk_parent, c
return
Credits go to BrianKamrany on Autohotkey Community.
Original post here.
(Un?)helpfully, your script works fine for me on Windows 10 / AHK as of 2016.
Here's my longer AHK script for coping with Mac-User-&-Apple-Keyboard syndrome:
AutoHotKey for a Mac User with an Apple keyboard on Windows.ahk
https://gist.github.com/chrisfcarroll/dddf32fea1f29e75f564
Related
I have a file with a column (5 in the pic) that is filled with X's. I need to replace those X's with different letters. However, I need a certain amount of rows in that column to be the same letter, and then for another set of rows to be another letter, and so on. Example shown in 2nd pic. To be more clear, I need lines 2-10 to have the letter A in column 5, lines 11-20 to letter B, lines 21-30 the letter C, and so on. Is there a way to do this in Linux replacing those X's in the file by giving the row/line ranges and the letter I want, but NOT saving to a new file? I need a faster way than by hand because I have over a million lines in the file, and I have about 5,000 files to change.
What I have
What I need
awk '{ match($0,$5);printf "%s%c%s\n",substr($0,1,RSTART-1),64+$6,substr($0,RSTART+RLENGTH) }' file
Using awk, use the match function to find the starting position of the 5th space delimited field. We then print the start of the line to the 5th field, the character code of 64 + the 6th delimited field and then the rest of the field.
sample used:
ATOM 1 CA HIE X 1 105.967 123.567 112.345 0.00 0.00
ATOM 1 CA HIE X 2 105.967 123.567 112.345 0.00 0.00
ATOM 1 CA HIE X 3 105.967 123.567 112.345 0.00 0.00
Output:
ATOM 1 CA HIE A 1 105.967 123.567 112.345 0.00 0.00
ATOM 1 CA HIE B 2 105.967 123.567 112.345 0.00 0.00
ATOM 1 CA HIE C 3 105.967 123.567 112.345 0.00 0.00
So I have two DataFrames: Historic and Applet.
Historic contains a list of all courses my school offered in the past and Applet is all courses that my school currently offers
I want to merge the two DataFrames so that any items in my Applet DataFrame that don't exist in Historic are added and any that do exist overwrite their copies in Historic (Some courses may have updated information and should overwrite their historic entries with that information..)
I'm currently using Historic.combine_first(Applet) to merge the two by on their Indexes. However, I want the duplicate entries to overwrite their Historic entries not just make a duplicate entry.
Code:
def update2(self):
historic = pd.read_csv('course_history.txt', header=None, sep='"', encoding = 'ISO-8859-1',
names=['Course_ID', 'Course_Title', 'Professor_Name','Meeting_Time','Enrollment','Room','Year','Term','Credit'],index_col=[0,6,7])
winnet = pd.DataFrame(self.data, columns =['Course_ID', 'Course_Title', 'Professor_Name','Meeting_Time','Enrollment','Room','Year','Term','Credit'] )
winnet.set_index(['Course_ID','Year','Term'], inplace=True)
historic3 = historic.combine_first(winnet)
Historic DataFrame:
Course_ID Year Term ...
AC 230 01 2020-21 May Accounting Systems Crouse, Justin D. ... ROOM NULL 1.00
AC 429 01 2020-21 May CPA Review Sommermeyer, Eric ... ROOM NULL 1.00
ART 150 01 2020-21 May 20th-Century Art, Media, & Design Fedeler, Barbara J. ... ROOM NULL 1.00
ART 208 01 2020-21 May Photography I Payne, Thomas R. ... ROOM NULL 1.00
PSY 222 01 2018-19 FA Cognitive Psychology Eslick Watkins, A ... ROOM NULL 1.00
Applet DataFrame:
Course_ID Year Term
PSY 101 01 2018-19 FA Introduction to Psychology Bane, C T H 9:35AM-11:15AM 40/44/0 LH 330 1.00
PSY 101 02 2018-19 FA Introduction to Psychology Eslick Watkins, A T H 1:00PM-2:40PM 40/43/0 SC 134 1.00
PSY 210 10 2018-19 FA Child Development Munir, S T H 9:35AM-11:15AM 30/10/0 LH 327 0.50
PSY 211 20 2018-19 FA Adolescent Development Munir, S T H 1:00PM-2:40PM 30/6/0 LH 330 0.50
PSY 222 01 2018-19 FA Cognitive Psychology Eslick Watkins, A T H 9:35AM-11:15AM 30/24/0 LH 324 1.00
You can use concat then drop_duplicates
cols = [columns_to_judge_duplicates]
combined = pd.concat([Applet, Historic])
combined = combined.drop_duplicates(subset=cols, method='first')
everyone!
I'd like to remove duplicates and keep lines with the highest value from one column (4th column) in a file with 4 fields. I must do this in a Linux server.
Before
gene subj e-value ident
g1 h1 0.05 75.5
g1 h2 0.03 60.6
g2 h7 0.00 80.5
g2 h9 0.00 50.3
g2 h4 0.03 90.7
g3 h5 0.10 30.5
g3 h8 0.00 76.8
g4 h11 0.00 80.7
After
gene subj e-value ident
g1 h1 0.05 75.5
g2 h4 0.03 90.7
g3 h8 0.00 76.8
g4 h11 0.00 80.7
Thank you so much and I'm sorry if I asked something repeated! But I didn't find an answer for my problem.
You can try this, if it is no problem to get the output without the header:
tail -n +2 file.txt | sort -k1,1 -k4,4rn | sort -uk1,1
Explanation:
tail -n +2 file.txt
will remove the headers so they don't get involved in all the sorting.
sort -k1,1 -k4,4rn
will sort by column 1 first (-k1,1) and then by column 4 numerically and in reverse order (-k4,4rn)
Finally:
sort -uk1,1
Will remove duplicates taking into account just the first column.
Be aware that -k1,1 means from column one to column one, hence -k4,4 is from column 4 to column 4. Adjust to fit your columns.
With GNU datamash tool:
datamash --headers -Wfs -g1 max 4 < file | cut -f1-4
The output:
gene subj e-value ident
g1 h1 0.05 75.5
g2 h4 0.03 90.7
g3 h8 0.00 76.8
g4 h11 0.00 80.7
An awk solution, but I like archimiro version for simplicity.
awk '
NR>1 && $1 in arr {
if ($4 > arr[$1][4])
split($0, arr[$1])
next
}
NR>1 {
arr[$1][1] = ""
split($0, arr[$1])
}
END {
for(i in arr) {
for(j in arr[i])
printf arr[i][j] "\t"
print ""
}
}
' data.file
The result:
g1 h1 0.05 75.5
g2 h4 0.03 90.7
g3 h8 0.00 76.8
g4 h11 0.00 80.7
I'm unfamiliar with the terminology of what I'm trying to do (which is making it difficult to find the solution), but I think you can figure out what I'm trying to do from the inputfile. Input file is .txt that is tab separated.
#input file begins here
21 00 0.005 12.0 0.006621 0.35365 0.16718
22 00 0.005 14.0 0.00662 0.34899 0.17206
23 00 0.005 16.0 0.006645 0.34523 0.17739
24 00 0.005 18.0 0.006696 0.33956 0.1815
25 00 0.005 20.0 0.006755 0.33477 0.18692
26 00 0.005 22.0 0.006797 0.33084 0.19178
27 00 0.005 24.0 0.006892 0.3265 0.19683
28 00 0.005 26.0 0.006965 0.32093 0.20256
29 00 0.005 28.0 0.007072 0.31631 0.20747
31 00 0.007 12.0 0.006158 0.38969 0.12999
32 00 0.007 14.0 0.006124 0.38578 0.13541
33 00 0.007 16.0 0.006136 0.38161 0.14018
34 00 0.007 18.0 0.006147 0.37697 0.1452
35 00 0.007 20.0 0.006193 0.37356 0.14999
36 00 0.007 22.0 0.006238 0.3673 0.15499
37 00 0.007 24.0 0.006276 0.36387 0.16037
38 00 0.007 26.0 0.00634 0.35855 0.16595
39 00 0.007 28.0 0.006417 0.35388 0.17118
40 00 0.007 30.0 0.006497 0.34844 0.17673
I would like to differentiate between these two blocks of data on the graph. The graph will be a 2D plot, with the top block's points in red and the bottom block's points in blue. The total inputfile is about 1000 lines long, with different vertical lengths; however, they are all appropriately separated with the newline character (\n).
I'm plotting columns 4 and 6 with the data set name (a.k.a. legend label) being column 3.
Here is how you can address the different points:
Your input file indeed consists of two data blocks, which can be selected with every for plotting: every :::0::0 selects only the first block, see the documentation or help every.
To use a red line color, just use e.g.
plot 'file.txt' linecolor rgb 'red'
To select columns 4 and 6 for plotting, use using 4:6.
Using the values of the third columns as key labels is not straightforward. If you know that it is a numerical value, than you can use the stats command to extract these single values (see e.g. Gnuplot: How to load and display single numeric value from data file):
stats 'file.txt' using 3 every :::0::0 nooutput
key1 = sprintf('%.3f', STATS_max)
stats 'file.txt' using 3 every :::1::1 nooutput
key2 = sprintf('%.3f', STATS_max)
If the column can also contain other values, or you want to maintain this same formatting, you need an external tool to extract the values for the title:
key1 = system('head -1 file.txt | cut -f 3')
key2 = system('tail -1 file.txt | cut -f 3')
So, alltoghether you script may look like the following:
stats 'file.txt' using 3 every :::0::0 nooutput
key1 = sprintf('%.3f', STATS_max)
stats 'file.txt' using 3 every :::1::1 nooutput
key2 = sprintf('%.3f', STATS_max)
plot 'file.txt' using 4:6 every :::0::0 linecolor rgb 'red' title key1,\
'' using 4:6 every :::1::1 linecolor rgb 'blue' title key2
I have 2 folders which contain pdb files. The names of files are same in these two folders. I would like to move the contents of files in folder1 to the corresponding files in folder 2.
1T15.pdb file in folder1
ATOM 15 OD1 ASP A 197 20.828 -9.158 15.428 1.00 57.11 O
ATOM 16 OD2 ASP A 197 20.170 -11.065 14.548 1.00 56.80 O
ATOM 17 N GLU A 198 25.562 -8.839 13.516 1.00 51.61 N
1T15.pdb file in folder2
ATOM 54 CZ ARG A 201 34.442 -11.903 22.369 1.00 35.51 C
ATOM 55 NH1 ARG A 201 33.939 -12.599 23.386 1.00 34.12 N
ATOM 57 N ALA A 202 35.516 -11.657 16.626 1.00 40.91 N
ATOM 58 CA ALA A 202 36.455 -11.766 15.529 1.00 49.63 C
Desired output
ATOM 54 CZ ARG A 201 34.442 -11.903 22.369 1.00 35.51 C
ATOM 55 NH1 ARG A 201 33.939 -12.599 23.386 1.00 34.12 N
ATOM 57 N ALA A 202 35.516 -11.657 16.626 1.00 40.91 N
ATOM 58 CA ALA A 202 36.455 -11.766 15.529 1.00 49.63 C
ATOM 15 OD1 ASP A 197 20.828 -9.158 15.428 1.00 57.11 O
ATOM 16 OD2 ASP A 197 20.170 -11.065 14.548 1.00 56.80 O
ATOM 17 N GLU A 198 25.562 -8.839 13.516 1.00 51.61 N
A common approach would be to use basename:
for i in folder1/*.pdb; do cat "$i" >> folder2/"$(basename $i)"; done
>> will create the file if not present, otherwise appends to it.