Questions tagged [hook]

A hook refers to replacing or extending a system or application's default behavior with a custom behavior for a specific event. For keyboard hooks prefer the tag [keyhook]. For git related hooking use the tag [githooks] alone. For hooking web services use the tag [webhooks] instead. For React hooks use tag[react-hooks].

What is it?

A hook refers to replacing or extending the default behavior with a custom behavior for specific events. The events may be operating system events, but also application events that are meant to be extended with hooks.

The hook may fully replace the default behavior. It may also just extend the default behavior for example by adding a listening or monitoring activity without changing the default behavior, or add an extra effect on the top of it.

Hooking and programming techniques

"Hook" is commonly used to describe replacing a function pointer in an existing data structure with a new function pointer that points to new code. This new code can extend the default behavior by calling the old function pointer before or after the new code executes, or the new code can replace / disable the existing behavior by not calling the old pointer.

Hooking is similar in concept to OOP inheritance, but is usually more dynamic (determined at runtime) than OOP inheritance.

Essentially it's a place in code that allows you to tap in to a module to either provide different behavior or to react when something happens. Hooks often (but not always) use callback functions. For example, you might hook an event system using hookEvent(Events.STARTUP, myCallbackFunction). You are passing a function pointer to the hookEvent function, so it knows what function to call when the event occurs.

How does it work?

Typically hooks are inserted while software is already running, but hooking is a tactic that can also be employed prior to the application being started. There are two techniques to achieve this:

  • Physical modification
  • Runtime modification

Related tags and disambiguation

  • For the hooks related to keyboard events, prefer the tag
  • For the hooking git events, you must use the tag preferably without the
  • For hooking web services with web service callbacks prefer the tag
  • For React hooks, prefer the tag

More Information

5710 questions
2
votes
2 answers

pre_controller hook does not load base classes like docs state?

According to the Codeignitor docs here: http://ellislab.com/codeigniter/user-guide/general/hooks.html it states: pre_controller Called immediately prior to any of your controllers being called. All base classes, routing, and security checks have…
user3488435
  • 23
  • 1
  • 4
2
votes
1 answer

Git setting to skip a pre-commit hook for certain files

Disclaimer: yes, I've read Skip Git commit hooks and I know about the -n flag, but this is not what I'm looking for. I have that pre-commit hook that runs in order to do some code prettifying (replace tabs with spaces, remove double empty lines,…
eckes
  • 64,417
  • 29
  • 168
  • 201
2
votes
3 answers

Function that remove specific lambda from a hook in Emacs

I found this macro, to run code for specific project path: (defmacro project-specifics (name &rest body) `(progn (add-hook 'find-file-hook (lambda () (when (string-match-p ,name (buffer-file-name)) …
jcubic
  • 61,973
  • 54
  • 229
  • 402
2
votes
2 answers

Xposed hook onto Android resource

I am trying to use Xposed on Android to hook onto an Android resource, in particular, Webview's loadUrl. The code below hooks onto loadUrl and if successful, prints a message onto the log. findAndHookMethod("com.example.webview.MainActivity",…
bunbun
  • 2,595
  • 3
  • 34
  • 52
2
votes
1 answer

How to share data between SpecFlow beforetestrun and aftertestrun hooks?

We have scenariocontext and featurecontext to share data between scenarios and features but is there a way to share data between the beforetestrun and aftertestrun? I am trying to kill the open browser processes at the end of the test run as…
user1809943
  • 141
  • 3
  • 9
2
votes
2 answers

Generating Smooth Normals from active Vertex Array

I'm attempting to hack and modify several rendering features of an old opengl fixed pipeline game, by hooking into OpenGl calls, and my current mission is to implement shader lighting. I've already created an appropriate shader program that lights…
Zain Syed
  • 443
  • 4
  • 12
2
votes
1 answer

Additional HipChat Heroku Deploy Hook Options

I was wondering how to display the commit message and committing user for a HipChat bot commit to a deployment hook for Heroku. I know this is the basic setup: heroku addons:add deployhooks:hipchat \ --auth_token=my_auth_token \ --room="My…
user1114864
  • 1,734
  • 6
  • 26
  • 37
2
votes
1 answer

wordpress the permalink action hook?

Is there any action hook for wordpress the_permalink ? For example, whenever the the_permalink function is triggered, I need to write a plugin that will try to edit the URL according to my needs, and then return the edited URL that will be…
Muhammad Sohail
  • 598
  • 7
  • 14
2
votes
3 answers

Using Perl to build a SVN post-commit hook: IRC Bot to print commit Message

I'm trying to build an IRC Bot which tells me in a private channel every commit-message which I want to know about. But I have trouble to get per #!/bin/bash REPOS="$1" REV="$2" # call bot with arguments reposname, revison and commit message in…
marvin2k
  • 1,573
  • 2
  • 14
  • 18
2
votes
2 answers

Wordpress init remove_action with conditional tags

I need to do this for a theme: remove_action( 'wp_head', 'rel_canonical' ); BUT I need to do that with conditional tags. The code below don't work. if(is_page('comment')) { remove_action( 'wp_head', 'rel_canonical' ); } AND I need to do this…
Jens Törnell
  • 23,180
  • 45
  • 124
  • 206
2
votes
0 answers

Can't capture window showing event with SetWinEventHook

I'm using the SetWinEventHook function to monitor windows as they appear and disappear, i.e. become visible and hidden, by using code similar to the one Raymond Chen provides in his article Using accessibility to monitoring windows as they come and…
Paul
  • 6,061
  • 6
  • 39
  • 70
2
votes
1 answer

Hooking a 64 bit process from 32 bit app

I'm using SetWindowHookEx to load a DLL into another process, but I need to be able to hook into both 32 and 64 bit processes. I guess I need two separate DLLs for that, but can I do it without creating two versions of the "launcher" app? I need to…
riv
  • 6,846
  • 2
  • 34
  • 63
2
votes
2 answers

Why do DirectX fullscreen applications give black screenshots?

You may know that trying to capture DirectX fullscreen applications the GDI way (using BitBlt()) gives a black screenshot. My question is rather simple but I couldn't find any answer: why? I mean technically, why does it give a black screenshot? I'm…
GuiTeK
  • 1,561
  • 5
  • 20
  • 39
2
votes
1 answer

Event-driven MVC application

I have a MVC application which uses events(hooks) and I have a question about when to trigger an event. There are three options: trigger in models(this approach will mess-up the code, but gain a little more flexibility) trigger in controllers(after…
Sorin Vladu
  • 1,768
  • 3
  • 21
  • 37
2
votes
1 answer

Calling/invoking a hook manually in Codeigniter

I searched for calling/invoking a hook manually and similar stuff on the web but couldn't find anything. Is there a such thing in codeigniter? I have a hook below which gets triggered as expected but just in case if doesn't, then I want to invoke it…
BentCoder
  • 12,257
  • 22
  • 93
  • 165