If you just detect enter key pressed at any time, use getchar() or cin.get() function.
C language
#include <stdio.h>
#include <windows.h> // for Sleep function
int main(void)
{
while(true){
if (getchar() == '\n') {
printf("Enter key is pressed");
Sleep(1000); //wait for check printed message.
break;
}
}
return 0;
}
C++
#include <iostream>
using namespace std;
int main() {
while (1) {
if (cin.get() == '\n') {
cout << "Enter key is pressed" << endl;
break;
}
}
return 0;
}
Method 2. get line
If you’d like to detect that only enter key is pressed without input another key before enter, use scanf() , fgets() or gets() in C language or getline() in C++
C language
#include <stdio.h>
#include <string.h>
#include <windows.h> // for Sleep function
int main(void)
{
while (1) {
//if (getchar() == '\n') {
char str[32];
gets(str);
if(strcmp(str,"")==0){
printf("Enter key is pressed");
Sleep(1000); //wait for check printed message.
break;
}
}
return 0;
}
C++
#include <iostream>
using namespace std;
int main() {
string str;
while (1) {
getline(cin, str);
if (str == "") {
cout << "Enter key is pressed" << endl;
break;
}
}
return 0;
}
Method 3. GetKeyState
GetKeyState() is only provided on Windows. You can get the current “state” of the key. It returns 0 when the key is not pressed.
When I create a new C/C++ project in VisualStudio, an header file named “pch.h” is generated.
GOAL
To understand what is pch.h and how to use it.
Environment
Windows 10 VisualStudio 2017
What is pch.h
pch.h is a precompiled header that is an header file where any stable header files such as Standard Library headers are included. You can add header files you’d like to pre compile. The precompiled header is compiled only when it, or any files it includes, are modified.
Start an application and kill it after a certain time.
Environment
macOS Catalina 10.15.5
ShellScript
sleep.sh
#!/bin/sh
open -a MyApp
sleep 60
killall MyApp
echo "stop"
open
The command “open” can open files and it takes some options. You can see options here. The -a option is for application.
open -a MyApp
kill/killall
The commands “kill” and “killall” can kill processes. “kill” takes PID(process id) and “killall” takes process name. You can stop and close an application with this command.
killall MyApp
sleep
The command “sleep” can delay for a specified time. Though “sleep” can take quantifiers such as 10s(second), 10m(minutes) and 10h(hours) in Linux, it can take number as seconds in OSX ([Tips]Why command “sleep 1m” doesn’t work in mac).
sleep 60
Execution
Open the terminal and input the sh file name.
% Documents/sh/sleep.sh
If the permission error occurred, change access permission with “chmod” command.
You can get the list of module search paths. Find the directory you’d like from the list.
>python
Python 3.8.6
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
---The list of module search paths---
Appendix
You can find the directory where python.exe is by using “where” command.
PID, the process ID, is a number used in some operating system kernels to identify processes uniquely.
Methods
Method 1
Open “Task Manager” and open “Details” tab. See the PID of each Process.
Method 2
Use tasklist command and you can get the list of currently running tasks.
>tasklist
Image Name PID Session Name Session# Mem Usage
============ ===== ============= ========= =========
System Idle 0 Services 0 8 K
System 4 Services 0 2,728 K
Registry 120 Services 0 36,960 K
...
add_action( 'wp_head', 'header_customize');
function header_customize() {
$header_tags = <<<EOM
<!--ADD YOUR HTML HERE such as <script src="..."></script>-->
EOM;
echo $header_tags;
}
The argument function header_customize() is added when wp_head() is called in functions.php of parent theme as below.
<?php wp_head(); ?>
You can see the code written in the source of your website.
Change the default font of your theme in WordPress to google fonts.
Environment
WordPress 5.5.1 Theme: Sparkling (I have child-theme sparkling-child)
What is Google Fonts?
Google font is abundant font set that can be used in websites without install and upload. It can be used by just putting code in your HTML.
We believe the best way to bring personality and performance to websites and products is through great design and technology. Our goal is to make that process simple, by offering an intuitive and robust collection of open source designer web fonts.